I want to send a raw http packet to a webserver and recieve its response but i cant find out a way to do it. im inexperianced with sockets and every link i find uses sockets to send udp packets. any help would be great.
相关问题
- Views base64 encoded blob in HTML with PHP
- Angular RxJS mergeMap types
- Laravel Option Select - Default Issue
- Multiple sockets for clients to connect to
- PHP Recursively File Folder Scan Sorted by Modific
If all you want to do is perform a GET request and receive the body of the response, most of the file functions support using urls:
For more than simple GETs, use curl (you have to compile it into php). With curl you can do POST and HEAD requests, as well as set various headers.
Take a look at this simple example from the
fsockopen
manual page:The connection to the server is established with
fsockpen
.$out
holds the HTTP request that’s then send withfrwite
. The HTTP response is then read withfgets
.cURL is easier than implementing client side HTTP. All you have to do is set a few options and cURL handles the rest.
If you need to set a header that cURL doesn't support, use the CURLOPT_HTTPHEADER option, passing an array of additional headers. Set CURLOPT_HEADERFUNCTION to a callback if you need to parse headers. Read the docs for
curl_setopt
for more options.