Like firebug shows ajax request made by javascript is there any similar tool for windows which can show http request made through CURL from PHP while working locally on WAMP ?
Thanks.
http://www.wireshark.org/ or http://www.effetech.com/sniffer/
Also see other answers
https://stackoverflow.com/questions/1437038/http-and-https-sniffer-for-windows
How to sniff http requests
Google "HTTP Analyzer", "Protocol Analyzer", "HTTP Sniffer" etc for alternatives.
Do you want the HTTP headers?
If you have curl on windows,
curl http://example.com -D -
gives you the HTTP headers also. ( the '-' after the '-D' tell it to spit it to stdout (works on *nix, not sure about windows) , you can replace the '-' with a filename
eg:
curl http://example.com -D headers.txt
)
Or you can look it up on the other side of the universe with Apache access logs (as you are working locally). I dont have Windows here, but you might have to configure it to log,
http://httpd.apache.org/docs/1.3/logs.html#accesslog
Fiddler should be able to catch curl too, and it has a quite complete interface.
Related
I want to know how can i check with domain name if website is missing content type sniffing header. Server is not mine, so I can not create php files inside or edit .htaccess file. i know that checking php version is possible with git bash and curl but is it possible to detect that missing header with curl too? or there is other way? (Only LEGAL of course)
Every major internet browser today (Chrome, Fx, MSIE...) lets you see in its developer tools the network transfers, including headers with each request and each response:
You can use the -D option wit curl:
-D, --dump-header <filename> Write the received headers to <filename>
curl http://whatever.com -D myheaders.txt
Then open myheaders.com and look for the header you want.
The URL in question : http://www.roblox.com/asset/?id=149996624
When accessed in a browser, it will correctly download a file (which is an XML document). I wanted to get the file in php, and simply display its contents on a page.
$contents = file_get_contents("http://www.roblox.com/asset/?id=149996624");
The above is what I've tried using (as far as I know, the page does not expect any headers). I get a 500 HTTP error. However, in Python, the following code works and I receive the file.
r = requests.get("http://www.roblox.com/asset/?id=147781188")
I'm confused as to what the distinction is between how these two requests are sent. I am almost 100% it is not a header problem. I've also tried the cURL library in PHP to no avail. Nothing I've tried in PHP seems to succeed with the URL (with any valid id parameter); but Python is able to bring success nonchalantly.
Any insight as to why this issue may be happening would be great.
EDIT : I have already tried copying Python's headers into my PHP request.
EDIT2 : It also appears that there are two requests happening upon navigating to the link.
Is this on a linux/mac host by chance? If so you could use ngrep to see the differences on the request themselves on the wire. Something like the following should work
ngrep -t '^(GET) ' 'src host 127.0.0.1 and tcp and dst port 80'
EDIT - The problem is that your server is responding with a 302 and the PHP library is not following it automatically. Cheers!
$output = file_get_contents("http://www.canadapost.ca/cpc2/addrm/hh/current/indexa/caONu-e.asp");
var_dump($output);
HTTP 505 Status means the webserver does not support the HTTP version used by the client (in this case, your PHP program).
What version of PHP are you running, and what HTTP/Web package(s) are you using in your PHP program?
[edit...]
Some servers deliberately block some browsers -- your code may "look like" a browser that the server is configured to ignore. I would particularly check the user agent string that your code is passing along to the server.
Check in your PHP installation (php.ini file) if the allow_url_fopen is enabled.
If not, any calls to file_get_contents will fail.
It works fine for me.
That site could be blocking the server that you're using to access it.
When you run the URL from your browser, your own ISP is used to get the information and display in your browser. But when you run from PHP, the ISP of your web host is used to get the information, then it passes it back to you.
Maybe you can do this to check and see what kind of headers its returning for you?
$headers=get_headers("http://www.canadapost.ca/cpc2/addrm/hh/current/indexa/caONu-e.asp");
print_r($headers);
I tried using curl to post to a local file and it fails. Can it be done? my two management systems are on the same server and it seems unnecessary to have it traverse the entire internet system just to go to a file on the same hard drive.
Using localhost didn't do the trick.
I also tried to $_SERVER[DOCUMENT_ROOT].'/dir/to/file.php' using post data. It's for an API that is encrypted, so I'm not sure exactly how it works. It's for a billing system I have and I just realized that it sends data back (API).
It's simply post data and an XML response. I could write an html form tag and input fields and get the same result, but there isn't really anything else to know.
The main question is: Does curl have the ability to post to a local file or not?
it is post data. it's for an API that is encrypted so i'm not sure exactly how it works
Without further details nobody can answer then what you should do.
But if it's indeed a POST receival script on the local server, then you can send a POST request to it using the URL:
$url = "https://$_SERVER[SERVER_NAME]/path/to/api.php";
And then receive its output from the cURL call.
$data = curl($url)->post(1)->postdata(array("billing"=>1234345))
->returntransfer(1)->exec();
// (you would use the cumbersome curl_setopt() calls instead)
So you get a XML or JSON or whatever response.
If they're on the same drive, then use file operations instead:
file_put_contents('/path/to/the/file', $contents);
Using CURL should only be done if you absolutely NEED the http layer to get involved for some reason, or if you're dealing with a remote server. Using HTTP would also mean you need to have the 'target' script be able to handle a file upload plus whatever other data you need to send, and then that script would end up having to do file operations ANYWAYS, so in effect you've gone on a round-the-world flight just so you can move from your living room to the kitchen.
file://locafilespec.ext worked for me. I had 2 files in the same folder on a linux box, in a folder that is not served by my webserver, and I used the file:// wrapper to post to file://test.php and it worked great. it's not pretty, but it'll work for dev until I move it to it's final resting place.
Does curl have the ability to post to a local file or not?
To curl local file, you need to setup HTTP server as file:// won't work, so:
npm install http-server -g
Then run the HTTP server in the folder where is the file:
$ http-server
See: Using node.js as a simple web server.
Then test the curl request from the command-line to localhost like:
curl http://127.0.0.1:8081/file.html
Then you can do the same in PHP.
I have a php script, called from a web page (server is Apache debian 6.03), which does a GET and a POST both using curl. The GET is fine. The POST fails if php curl goes directly to the network but works fine if I use charles as a proxy. (Haven't tried other proxies.)
In particular, if I add
curl_setopt($ch, CURLOPT_PROXY, "localhost:8888" );
to my script (with charles runningon 8888) it succeeds. Otherwise I get:
"HTTP/1.1 400 Bad Request".
Any ideas greatly appreciated.
Oops. My script used cookies in the post and there was white space at the beginning of the cookie string which I constructed. Adding a 'trim' fixed the problem.
Sorry.