If an http request fails, the following code is the HTTP request code.
The second request failed. could you tell me where the error was?
Normal process: send an http request, 401 response, send an http request with verification again, and return 200. End.
Note: the account and password in the code are all default, so the account and password in the data returned for the first time are not extracted. The account and password in the second request use the default data.
Function Socket_Connect_HTTP_Post ($ server, $ port, $ dir, $ file, $ data, $ type = ''){
$ Send_url = str_replace ("% 2F", "/", rawurlencode (rawurldecode (urldecode ($ dir. $ file ))));
$ Method = "POST ";
$ Http_header_array ["ALL"] [] = "Accept :*/*";
$ Http_header_array ["ALL"] [] = "Referer: http: //". $ server ."/";
$ Http_header_array ["ALL"] [] = "Accept-Language: en-us, zh-cn ";
$ Http_header_array ["ALL"] [] = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1 )";
$ Http_header_array ["ALL"] [] = "Connection: Keep-Alive ";
$ Http_header_array ["ALL"] [] = "Host:". $ server;
$ Http_header_array ["ALL"] [] = "urn: po-processor ";
If (! Empty ($ type )){
$ Http_header_array ["ALL"] [] = "Authorization: Digest realm = \" www.fkhl.sh.cn \ ", username = \" FHL3301009 \ ", nonce = \" signature = \", uri = \ "/ipcam/soapservice \", nc = 00000001, cnonce = \ "51c3f331ca564506784 \", response = \ "reply \", qop = \ "auth \"";
}
$ Http_header_array ["ALL"] [] = "SOAPAction: http://www.liveipc.com/UserService/UserOperation ";
$ Http_header_array ["POST"] [] = "Cache-Control: no-cache ";
$ Http_header_array ["POST"] [] = "Content-Type: text/xml ";
$ Http_header_array ["POST"] [] = "Content-Length:". strlen ($ data );
If (is_array ($ http_header_array ["ALL"]) {
$ Http_header_str_all = implode ("\ r \ n", $ http_header_array ["ALL"]);
}
If (is_array ($ http_header_array [$ method]) {
$ Http_header_str_all. = "\ r \ n". implode ("\ r \ n", $ http_header_array [$ method]);
}
$ Send_all = "POST". $ send_url. "HTTP/1.1 \ r \ n". $ http_header_str_all. "\ r \ n ";
$ Send_all. = $ data. "\ r \ n ";
$ Fp_send = fsockopen ($ server, $ port, $ errno, $ errstr, 30 );
If ($ fp_send)
{
$ Can_rcv = 0;
Fputs ($ fp_send, $ send_all );
Stream_set_timeout ($ fp_send, 120 );
While (! Feof ($ fp_send ))
{
$ Content_t = fgets ($ fp_send, 1024 );
If (trim ($ content_t) = "")&&! $ Can_rcv)
{
$ Can_rcv = 1;
$ Content_t = fgets ($ fp_send, 1024 );
}
If ($ can_rcv = 1 and strlen ($ content_t)> 5)
{
$ Reply_str. = $ content_t;
}
}
$ Stream_status = stream_get_meta_data ($ fp_send );
Fclose ($ fp_send );
If ($ stream_status [timed_out])
{
$ Reply_str = "";
}
}
Return $ reply_str;
}
$ Soap_data ="
1.0.0
GBK
UserRegistration
C7c92fc2882f41f92249fac90aad7bb6
0
Test07
123456
123456
Shengxiumei@fkhl.sh.cn
";
// Soap transmission
// The first http request
$ Ret_str = Socket_Connect_HTTP_Post ("www.liveipc.com", "80", "/ipcam/soapservice", "", $ soap_data); // data packet
// Second http request
If ($ ret_str ){
$ Result = Socket_Connect_HTTP_Post ("www.liveipc.com", "80", "/ipcam/soapservice", "", $ soap_data, 200 );
}
Reply to discussion (solution)
Is there a prompt for the error code? This pile of code can be selected in the editor box, otherwise it will be too messy.