How to POST data from a PHP file POST data, no form and hidden variables

xiaoxiao2021-03-06  75

You can use the following functions: Function PostTohost ($ URL, $ DATA) {$ URL = PARSE_URL ($ URL); if (! $ Url) Return "COULDN't Parse URL"; if (! Isset ($ URL [' Port ']) {$ URL [' Port '] = "";} if (! isset ($ URL [' Query ']) {$ URL [' Query '] = ""} $ encoded = "" While (List) = Each ($ data)) {$ encoded. = ($ encoded? "&": "); $ encoded. = rawurlencode ($ k)." = ". Rawurlencode ($ V);} $ fp = fsockopen ($ URL ['Host'], $ URL ['Port']: 80); if (! $ fp) Return "Failed to Open Socket To $ URL [Host] "; FPUTS ($ FP, SPRINTF (" Post% S% S% S HTTP / 1.0 / N ", $ URL ['PATH'], $ URL ['Query']?": "", $ URL ['Query']); FPUTS ($ FP, "Host: $ URL [Host] / N"); FPUTS ($ FP, "Content-Type: Application / X-WWW-Form-Urlencoded / N "); FPUTS ($ FP," Content-Length: ":". Strlen ($ encoded); "/ n"); FPUTS ($ FP, "Connection: Close / N / N"); FPUTS ($ FP, "$ encoded / N"); $ line = fgets ($ FP, 1024); if (! EREGI ("^ HTTP / 1 / .. 200", $ LINE)) RETURN; $ Results = ""; $ inheader = 1; While (! Feof ($ fp)) {$ line = fgets ($ fp, 1024); if ($ inheader && ($ line == "/ n" || $ line == "/ r / n") ) {$ inheader = 0;} elseif (! $ inhead ER) {$ results. = $ line;}} fclose ($ fp); return $ results;}?>

It can also be

$ URL = "www.mysite.com/test.php"; $ ch = curl_init (); curl_setopt ($ Ch, curlopt_url, "https: // $ url"); curl_setopt ($ ch, curlopt_post, 1); curl_setopt ($ CH, CURLOPT_POSTFIELDS, "DATA1 = Blah & Data2 = Blah"); CURL_EXEC ($ CH); curl_close ($ ch);?>

转载请注明原文地址:https://www.9cbs.com/read-93769.html

New Post(0)