CURL gives 505

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

neelu7779
Forum Newbie
Posts: 12
Joined: Tue Sep 08, 2009 9:50 am

CURL gives 505

Post by neelu7779 »

HI all,

I wrote a php script which use curl Following is the code snippet.

$URL = "http://domainname.com:8080/API.jsp?username=neelu&password=20sfsdfs&sendername=Saar IT&mobileno=91".$_POST['nmCellPhone']."&message=".$SMSMsg;
$cURLhandle = curl_init();
curl_setopt($cURLhandle, CURLOPT_URL, $URL);
curl_setopt($cURLhandle, CURLOPT_HTTPGET, true);
curl_setopt($cURLhandle, CURLOPT_HEADER, false);
curl_setopt($cURLhandle, CURLOPT_RETURNTRANSFER , true);
curl_exec($cURLhandle);
echo('<br />'.curl_getinfo($cURLhandle, CURLINFO_HTTP_CODE).'<br />');
echo('<br />'.curl_getinfo($cURLhandle, CURLINFO_EFFECTIVE_URL));
echo('<br />'.curl_error($cURLhandle));
curl_close($cURLhandle);


this code shows the getinfo http code value =505. can some one point out the mistake.

Thanks
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: CURL gives 505

Post by Eric! »

Without knowing the details of the site you are trying to access, I can't really help. Try turning on the debug info and dumping it into a file

Code: Select all

//redirect stderr to file stream
$fp = fopen("debug.txt","w");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_STDERR, $fp);
//don't forget fclose at the end...
neelu7779
Forum Newbie
Posts: 12
Joined: Tue Sep 08, 2009 9:50 am

Re: CURL gives 505

Post by neelu7779 »

hi,

I can not post the exact url as it contains username and password.
I have tried turning verbose on . But it does not show any thing in the browser.

Thanks for the reply.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: CURL gives 505

Post by Eric! »

Use the code snippet I posted. It will redirect the output to a known location (i.e. a file) that you can then view.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: CURL gives 505

Post by Darhazer »

505 is version not supported.
Is it https or it's really 8080, http?
what's happening when you are just opening the url in the browser?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: CURL gives 505

Post by John Cartwright »

I like to use a program called Fiddler2, which is an Http Proxy debugging tool. It is very useful for comparing requests made by a browser and through various programming tools.

As for getting an HTTP 505 response, you can try forcing curl to use an older version of the http protocol (1.0).

Code: Select all

curl_setopt($curlHandle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: CURL gives 505

Post by Eric! »

I suggest you try putting in those 4 lines of code first and then looking at the debug.txt file. It will tell you what the server http version is, and what it doesn't like about your request.

However I often end up using a proxy tool like Fiddler2 or WebScarab to help capture the data when it is a complicated cURL configuration.
neelu7779
Forum Newbie
Posts: 12
Joined: Tue Sep 08, 2009 9:50 am

Re: CURL gives 505

Post by neelu7779 »

hi,
I tried a url without spaces. and that url gives the outputin the browser correctly.

I am using curl to send a sms using the url given by sms gateway company. If there are no spaces in the url it works. But not when there are spaces in the url.

How to work around the spaces?? Can you suggest??
neelu7779
Forum Newbie
Posts: 12
Joined: Tue Sep 08, 2009 9:50 am

Re: CURL gives 505

Post by neelu7779 »

I tried the debug.txt thing. Following is the output:::

* About to connect() to bulksms.mysmsmantra.com port 8080 (#0)
* Trying 216.154.213.157... * connected
* Connected to bulksms.mysmsmantra.com (216.154.213.157) port 8080 (#0)
> GET /WebSMS/SMSAPI.jsp?username=neelu77&password=lkjeee&sendername=Saar IT&mobileno=919920858379&message=Dear qq, You are now registered with SAAR IT SERVICES.Please Check email to activate account. HTTP/1.0
Host: bulksms.mysmsmantra.com:8080
Accept: */*

< HTTP/1.1 505 HTTP Version Not Supported
< Server: Apache-Coyote/1.1
< Date: Wed, 09 Sep 2009 02:23:00 GMT
< Connection: close
* Closing connection #0
neelu7779
Forum Newbie
Posts: 12
Joined: Tue Sep 08, 2009 9:50 am

Re: CURL gives 505

Post by neelu7779 »

hi,

I have also tried forcing curl to use http version 1.0. Did not work..
neelu7779
Forum Newbie
Posts: 12
Joined: Tue Sep 08, 2009 9:50 am

Re: CURL gives 505

Post by neelu7779 »

hi all,

It is working now. I replaced all the spaces with the %20 and it is now working.

I still have a doubt.. Why was not the verbose option working??? Please clear my doubt.

Thanks all for your suggestions and help. Thank you so much....
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: CURL gives 505

Post by Eric! »

verbose did work, that's what was dumped into the debug file. You just needed to direct the server to where to put the verbose output (debug.txt).

From your debug file you need to force 1.0
HTTP/1.0
Host: bulksms.mysmsmantra.com:8080
Accept: */*

< HTTP/1.1 505 HTTP Version Not Supported
And you always have urlencode strings that you are using (i.e. the %20 for spaces). Try this next time

Code: Select all

$url="http://my.site.com/test.php?".urlencode("cmd=I Need To Login&Download Stuff");
This does the following types of converstions:

Code: Select all

'?' => %3F
'=' => %3D
' ' => %20
'(' => %28
')' => %29
'&' => %26
'@' => %40
The reverse function is urldecode();
Last edited by Eric! on Fri Sep 18, 2009 7:29 am, edited 1 time in total.
neelu7779
Forum Newbie
Posts: 12
Joined: Tue Sep 08, 2009 9:50 am

Re: CURL gives 505

Post by neelu7779 »

Thanks for the tip.

It worked earlier in the morning. but now it has stopped working again.

Following is the content of debug.txt.::::::::::
* About to connect() to bulksms.mysmsmantra.com port 8080 (#0)
* Trying 216.154.213.157... * connected
* Connected to bulksms.mysmsmantra.com (216.154.213.157) port 8080 (#0)
> GET /WebSMS/SMSAPI.jsp?username=neelu&password=qweqwe&sendername=Saar%20IT&mobileno=919920858379&message=Dear%20zz,%20You%20are%20now%20registered%20with%20SAAR%20IT%20SERVICES.Please%20Check%20email%20to%20activate%20account. HTTP/1.1
Host: bulksms.mysmsmantra.com:8080
Accept: */*

< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=AE76AE059C05F1F53CD01D5D86156BAD; Path=/WebSMS
< Content-Type: text/html;charset=UTF-8
< Content-Length: 70
< Date: Wed, 09 Sep 2009 15:54:48 GMT
* Connection #0 to host bulksms.mysmsmantra.com left intact
* Closing connection #0

what could be the reason. I changed the code a little.. Following is the latest piece of code.



$cURLhandle = curl_init();
curl_setopt ($cURLhandle, CURLOPT_STDERR, $fp);
curl_setopt($cURLhandle, CURLOPT_VERBOSE, 1);
curl_setopt($cURLhandle, CURLOPT_URL, $URL);
curl_setopt($cURLhandle, CURLOPT_RETURNTRANSFER , true);
curl_exec($cURLhandle);
curl_close($cURLhandle);
fclose($fp);
neelu7779
Forum Newbie
Posts: 12
Joined: Tue Sep 08, 2009 9:50 am

Re: CURL gives 505

Post by neelu7779 »

hi,

It works from the development enviornment, but not live. debug.txt on live server says connectin refused.
gives http code 0.
Any suggestions?
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: CURL gives 505

Post by Eric! »

I don't know. It looks like you are trying to use a gateway for SMS messages that belongs to someone else. Perhaps they are blocking your domain. You might try asking them why your connection was refused. Likewise your "live" server might be blocking access to that port with a firewall.

You can check this by running telnet on your live server

telnet bulksms.mysmsmantra.com 8080 (followed by hitting return a few times slowly)

If the connection is refused then the port is blocked.
Post Reply