curl POST请求参数有中文后台报错,英文可以请求成功 Invalid UTF-8 start byte 0xba

Invalid UTF-8 start byte 0xba

网上搜,把cmd编辑环境改成utf-8 chcp 65001 改成utf-8后连中文都输不了。

城里俊男多 这个问题我也没解决。还是用soapui 或者postman吧
大约一年之前 回复
緣木求魚 一样的问题,求助》》
大约一年之前 回复
Csdn user default icon

<div class="post-text" itemprop="text"> <p>I'm having some issues with calling WordPress XML-RPC via cURL in PHP. It's a hosted blog, and the XML-RPC file is located at <a href="" rel="nofollow"></a>.</p> <p>Starting yesterday (or at least, yesterday was when it was noticed), cURL has been failing with error #52: Empty reply from server.</p> <p>The code snippet we're using is below:</p> <pre class="lang-php prettyprint-override"><code>$ch = curl_init(''); curl_setopt_array($ch, [ CURLOPT_HEADER =&gt; false, CURLOPT_HTTPHEADER =&gt; [ 'Content-Type: text/xml' ], CURLOPT_POSTFIELDS =&gt; xmlrpc_encode_request('wp.getPosts', [ 1, WP_USERNAME, WP_PASSWORD, [ 'number' =&gt; 15 ] ]), CURLOPT_RETURNTRANSFER =&gt; true ]); $ret = curl_exec($ch); $data = xmlrpc_decode($ret, 'UTF-8'); </code></pre> <p>Using cURL directly however, everything returns exactly as expected:</p> <pre class="lang-php prettyprint-override"><code>$output = []; exec('curl -d "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;&lt;methodCall&gt;&lt;methodName&gt;wp.getPosts&lt;/methodName&gt;&lt;params&gt;&lt;param&gt;&lt;value&gt;&lt;int&gt;1&lt;/int&gt;&lt;/value&gt;&lt;/param&gt;&lt;param&gt;&lt;value&gt;&lt;string&gt;' . WP_USERNAME . '&lt;/string&gt;&lt;/value&gt;&lt;/param&gt;&lt;param&gt;&lt;value&gt;&lt;string&gt;' . WP_PASSWORD . '&lt;/string&gt;&lt;/value&gt;&lt;/param&gt;&lt;param&gt;&lt;value&gt;&lt;struct&gt;&lt;member&gt;&lt;name&gt;number&lt;/name&gt;&lt;value&gt;&lt;int&gt;15&lt;/int&gt;&lt;/value&gt;&lt;/member&gt;&lt;/struct&gt;&lt;/value&gt;&lt;/param&gt;&lt;/params&gt;&lt;/methodCall&gt;"', $output); $data = xmlrpc_decode(implode('', $output), 'UTF-8'); </code></pre> <p>We've been successfully able to query WordPress since July 2013, and we're at a dead-end as to why this has happened. It doesn't look like PHP or cURL have been updated/changed recently on the server, but the first code snippet has failed on every server we've tried it on now (with PHP 5.4+).</p> <p>Using the <a href="" rel="nofollow"></a> link gives the same issue.</p> <hr> <p>Is there anything missing from the PHP code that would cause this issue? That it's suddenly stopped working over 12 months down the line is what has flummoxed me.</p> </div>

Php curl post数据参数有时会发送为空

<div class="post-text" itemprop="text"> <p>I am trying to call service with three parameters: uri, code and type. But sometimes "type" parameter posting empty, sometimes posting correct. So service call sometimes successfull, sometimes fail. I don't change anything but parameter "type" sometimes empty. How can ı solve this problem ?</p> <pre><code>$curl_post_data = array( "uri" =&gt; $uri, "code" =&gt; $code, "type" =&gt; $type ); $post_data = http_build_query($curl_post_data); $curl = curl_init($service_url); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_HTTPAUTH, xxx); curl_setopt($curl, CURLOPT_USERPWD, xxx); curl_setopt($curl, CURLOPT_PROXY, 'xxx'); curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'xxxx'); curl_setopt($curl, CURLOPT_PROXYPORT, xxx); curl_setopt($curl, CURLOPT_PROXYAUTH, xxx); $curl_response = curl_exec($curl); if (false === $curl_response) { return null; } </code></pre> </div>

使用数组参数将POST cURL PHP请求转换为cURL命令行

<div class="post-text" itemprop="text"> <p>I wrote this coden which is OK :</p> <pre><code>$veh['vehicleClass'] = 'Car'; $veh['category'] = 'Van'; $veh['make'] = 'RENAULT'; $veh['model'] = 'Scenic'; $veh['modelDescription'] = 'Turbopoooower'; $veh['firstRegistration'] = "201606"; $veh['mileage'] = "500"; $veh['damageUnrepaired'] = true; $veh['condition'] = "USED"; $veh['internalNumber'] = "12"; $veh['price']['consumerPriceGross'] = "5400"; $ch = curl_init(); $proxy = PROXY_MOBILE_DE; $proxy_port = PROXY_PORT_MOBILE_DE; $loginpassw = LOGINPASSWD_MOBILE_DE; $url=''; $headers = array(); $headers[] = "Content-Type: application/"; curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port); curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, $loginpassw); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($vehicle)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $data = curl_exec($ch); curl_close($ch); </code></pre> <p>I want to convert this code into cURL command line. I've tried this :</p> <pre><code>curl -k -x -basic -u XXX:YYY -d "vehicleClass=Car" -d "category=Van" -d "make=RENAULT" -d "model=Scenic" -d "modelDescription=Turbopoooower" -d "condition=USED" -d "damageUnrepaired=true" -d "firstRegistration=201606" -d "internalNumber=13" -d "mileage=500" -d "price[consumerPriceGross]=5400" -X POST "" -H "Accept: application/ </code></pre> <p>but this cURL command line doesn't work, maybe something wrong link to parameter price[consumerPriceGross]... Any idea ?</p> </div>


<div class="post-text" itemprop="text"> <p>I'm trying to send cURL request to get response from payment service. The cURL request looks like:</p> <pre><code>curl -X POST \ -d 'grant_type=client_credentials&amp;client_id=CLIENTID&amp;client_secret=CLIENTSECRET' </code></pre> <p>My code in Symfony is:</p> <pre><code> $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,""); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array( "grant_type" =&gt; "client_credentials", "client_id" =&gt; $client_id, "client_secret" =&gt; $client_secret )) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec ($ch); curl_close($ch); var_dump($server_output); </code></pre> <p>But I always got false. What should I do to send curl request and get answer from payment service?</p> </div>

PHP curl POST请求与JSON响应

<div class="post-text" itemprop="text"> <p>I'm trying to send post data and receive an SID from an api(qbittorrent) to send with a get request later. I'm currently stuck with an OK response but the json is NULL. Here's my code:</p> <pre><code>&lt;?php $ch = curl_init(); $fields = array( 'username'=&gt;'Admin','password'=&gt;'mypassword'); $postvars = ''; foreach($fields as $key=&gt;$value) { $postvars .= $key . "=" . $value . "&amp;"; } $postvars = rtrim($postvars, '&amp;'); $url = ""; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0); $headers= array('Accept: application/json','application/x-www-form-urlencoded'); curl_setopt($ch,CURLOPT_HTTPHEADER, $headers); curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars); curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3); curl_setopt($ch,CURLOPT_TIMEOUT, 20); $response = curl_exec($ch); var_dump(json_decode($response, true)); print "curl response is:" . $response; curl_close ($ch); ?&gt; </code></pre> <p>You can see the API documentaiton here <a href="" rel="nofollow"></a></p> <p>I was able to get the json using powershell as simply as :</p> <pre><code>$prms = @{username="Admin";password="mypassword"} $res = Invoke-WebRequest -Method POST -Body prms -UseBasicParsing </code></pre> <p>but I'm unable to do so with php! If you also feel like heading me right for the get request using the SID as a cookie, i'll be more than welcome :)</p> </div>


<div class="post-text" itemprop="text"> <p>I am attempting to query the NOTAM database (<a href="" rel="nofollow"></a>) in order to have the server parse the NOTAMs for display on a map, code is PHP.</p> <p>I'm using cURL to send the POST data, however, the server is returning an "invalid request". Here is the POST data I'm sending to the server. It is exactly what is sent during a request from the homepage (discovered using Fiddler). The NOTAMs needed are the "RKRR" ICAO (airport code for Incheon Center here in Korea). </p> <p>What am I missing here?</p> <pre><code>$url = ""; $ch = curl_init($url); $header = array('Host:', 'Content-Type: application/x-www-form-urlencoded', 'Connection: keep-alive', 'Cache-Control: max-age=0', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/*;q=0.8', 'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36', 'Referer:', 'Accept-Encoding: gzip,deflate', 'Accept-Language: en-US,en;q=0.8', 'Origin:'); $data = 'retrieveLocId=rkrr&amp;reportType=Raw&amp;submit=View+NOTAMSs&amp;actionType=notamRetriealByICAOs'; curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); echo $response; curl_close($ch); </code></pre> <p>Thanks for the help!</p> </div>


<div class="post-text" itemprop="text"> <p>I am attempting to upload a file using php to a website that allows files to be uploaded through a form. When I try to run the code, I get a "Bad Request (Invalid Number)" error. Then when I enabled the cURL to fail on error with <code>CURLOPT_FAILONERROR</code> I get a "400 error". I think I've typed in everything correctly, I've downloaded files from the same website on a similar form they have.</p> <pre><code>$Submitted_ImportFile = realpath($Submitted_ImportFile); $postdata = array( 'NOSAVE___Form_Submission_Token' =&gt; $NOSAVE___Form_Submission_Token, 'import_type' =&gt; $import_type, 'span_Customers_BillingAddresses' =&gt; $Customers_BillingAddresses, 'span_Customers_ShippingAddresses' =&gt; $Customers_ShippingAddresses, 'span_TrackingNumbers_status' =&gt; $TrackingNumbers_status, 'span_TrackingNumbers_email' =&gt; $TrackingNumbers_email, 'Submitted_ImportFile' =&gt; '@'.$Submitted_ImportFile, 'OVERWRITE' =&gt; $OVERWRITE, 'Submit' =&gt; 'Upload my files' ); foreach ($postdata as $key =&gt; $value) { if (strlen($value) &lt; 1) { unset($postdata[$key]); }; }; // $postdata_encoded = http_build_query($postdata).'&amp;Submitted_ImportFile=@'.$Submitted_ImportFile; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url.'admin/db_import.asp?UploadID='.$UploadID); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0'); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt ($ch, CURLOPT_REFERER, $url); // curl_setopt ($ch,CURLOPT_FAILONERROR, true); // Temporarly added to diagnose issue curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $output = curl_exec ($ch); // $error = curl_error($ch); // Returns a 400 error </code></pre> <p>Here is the array containing all the POST data that is sent:</p> <pre><code>Array ( [NOSAVE___Form_Submission_Token] =&gt; 0D047D55CF3644818EBFEEEF607AD65D [import_type] =&gt; Customers [Submitted_ImportFile] =&gt; @/home/kudchcx/public_html/alpha_test/Customers_test.csv [OVERWRITE] =&gt; Y [Submit] =&gt; Upload my files ) </code></pre> <p>I've checked the website forms and used javascript to make sure I have all the necessary fields. I am at a loss for this issue.</p> </div>

php发送http post请求,用的是curl方法,我该如何接收这个post请求的数据呢

curl方法如下: function request_by_curl($remote_server, $post_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $remote_server); curl_setopt($ch, CURLOPT_POSTFIELDS, 'mypost=' . $post_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, "'s CURL Example beta"); $data = curl_exec($ch); curl_close($ch); return $data; } 我将一个数据从网站a发送到网站b,a和b是两个完全不同的网站,我该如何在 网站b中接收那个数据,能具体一点说明一下吗,最好有个范例 通过这样能得到吗 $ch = curl_init(); $data = curl_exec($ch); curl_close($ch); return $data;


<div class="post-text" itemprop="text"> <p>I am trying to send username and password through post request to login page on my localhost. I am using below code to generate request and send it to the page </p> <pre><code>$url='http://localhost/index.php'; $fields = array('username' =&gt; 'admin', 'password' =&gt; '1234'); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($fields)); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $result = curl_exec($ch); curl_close($ch); echo $result; </code></pre> <p><strong>Edit</strong><br> print_r(curl_getinfo($ch)); prints this information<br> Array ( [url] =&gt; <a href="" rel="nofollow"></a> [content_type] =&gt; text/html [http_code] =&gt; 200 [header_size] =&gt; 380 [request_size] =&gt; 182 [filetime] =&gt; -1 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 2.234 [namelookup_time] =&gt; 0.063 [connect_time] =&gt; 0.063 [pretransfer_time] =&gt; 0.063 [size_upload] =&gt; 28 [size_download] =&gt; 2322 [speed_download] =&gt; 1039 [speed_upload] =&gt; 12 [download_content_length] =&gt; 2322 [upload_content_length] =&gt; 28 [starttransfer_time] =&gt; 2.234 [redirect_time] =&gt; 0 [certinfo] =&gt; Array ( ) [primary_ip] =&gt; ::1 [primary_port] =&gt; 80 [local_ip] =&gt; ::1 [local_port] =&gt; 54953 [redirect_url] =&gt; ) Array ( [Host] =&gt; localhost [Accept] =&gt; <em>/</em> [Content-Length] =&gt; 28 [Content-Type] =&gt; application/x-www-form-urlencoded )</p> <p>The request is generated and I receive HTTP 200, OK status as response. The request is not sending any parameters with it, and in response I receive normal login form instead of after login screen.</p> <p>Anyone please tell me what is wrong with above code.</p> <p>I have tried same with stream_context_create and file_get_contents but same reponse is generated in both cases(login form instead of post login screen) like they are receving any parameters.</p> </div>

服务器更改后失败的cURL POST请求

<div class="post-text" itemprop="text"> <p>So I have a script to manage game options and it worked quite well a few weeks ago. However, game server changed and my script can't handle POST requests through cURL anymore.</p> <p>This works fine:</p> <pre><code>$curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "".$player); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_ENCODING, ""); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($curl, CURLOPT_COOKIEJAR, $_SERVER["DOCUMENT_ROOT"].'/vdod/cookies/'.$_SESSION["operator"].'.txt'); curl_setopt($curl, CURLOPT_COOKIEFILE, $_SERVER["DOCUMENT_ROOT"].'/vdod/cookies/'.$_SESSION["operator"].'.txt'); curl_exec($curl); </code></pre> <p>I get desired output. However, the code that goes right after it:</p> <pre><code>curl_setopt($curl, CURLOPT_URL, "".$player); curl_setopt($curl, CURLOPT_POSTFIELDS, "product=".$fetchSupplies["gift_quality"]."-GIFT&amp;quantity=".$fetchSupplies["gift_amount"]); curl_exec($curl); </code></pre> <p>gives me this result:</p> <pre><code>HTTP/1.1 302 Found Date: Fri, 14 Mar 2014 12:19:41 GMT Server: Apache/2.4.6 (Ubuntu) Location: Content-Language: en-US Content-Length: 0 Connection: close Content-Type: text/html HTTP/1.1 200 OK Date: Fri, 14 Mar 2014 12:19:41 GMT Server: Apache/2.4.6 (Ubuntu) Content-Language: en-US Vary: Accept-Encoding Content-Encoding: gzip Content-Length: 22927 Connection: close Content-Type: text/html;charset=UTF-8 </code></pre> <p>POST request failed. Game sends back the message about an uknown error and I noticed that headers show that Content-Length is... 0.</p> <p>All variables are correct, I debugged it. </p> <p>I just don't know how to handle that. How to make POST requests available again.</p> <p>PS: The thing is, only THIS module is screwed up with POST requests. I can still send automated messages in game (it's using cURL POST as well). Why this particular returns Content-Length: 0?</p> <p>PS2: Yes, I tried to include</p> <pre><code>curl_setopt($curl, CURLOPT_POST, 1); </code></pre> <p>and nothing happened.</p> <p>Help, anybody?</p> </div>


post参数放url后面与放body中的区别,为什么我将参数放在body里面,服务器端跟我说 接收不到我提交的数据 ---------------------------- 再详细一点,后台给了一个接口,是post请求,但是请求是通过URL拼接成的,就跟get 请求一样,所有的参数、数据都在URL里面,那么参数放url后面和放body里面有什么 区别?


<div class="post-text" itemprop="text"> <p>any help is very appreciated, thanks in advance.</p> <p>my storeCallback.php file which i have hosted at: <a href="http://xxxxx/storeCallback.php" rel="nofollow noreferrer">http://xxxxx/storeCallback.php</a></p> <pre><code>&lt;?php die(var_dump($_REQUEST)); </code></pre> <p>and i am creating a post json raw request as: </p> <p>1.</p> <pre><code>$url = "http://xxxxx/storeCallback.php/storeCallback.php"; $body =['foo' =&gt; 'bar']; $body_string = json_encode($body); $header = array( 'Accept: application/json', 'Content-Type: application/json', 'Content-Length: '.strlen($body_string), ); $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $body_string); $json_response = curl_exec($curl); $response = json_decode($json_response, true); die(var_dump($response)); </code></pre> <p>2.</p> <pre><code>$url = "http://xxxxx/storeCallback.php/storeCallback.php"; $body =['foo' =&gt; 'bar']; $body_string = json_encode($body); $header = array( 'Accept: application/json', 'Content-Type: application/json', 'Content-Length: '.strlen($body_string), ); $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $body_string); $json_response = curl_exec($curl); $response = json_decode($json_response, true); die(var_dump($response)); </code></pre> <p>3.</p> <pre><code>&lt;?php require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client(); $response = $client-&gt;post('http://xxxxx/storeCallback.php/storeCallback.php', [ GuzzleHttp\RequestOptions::JSON =&gt; ['for' =&gt; "bar"], ]); echo $response-&gt;getBody()-&gt;getContents(); </code></pre> <p><strong>Nothing is working, in all cases response is [] (empty array)</strong> but sending request like <a href="http://xxxxx/storeCallback.php/storeCallback.php?foo=bar" rel="nofollow noreferrer">http://xxxxx/storeCallback.php/storeCallback.php?foo=bar</a> is working</p> </div>

CURL POST请求问题,获取curl_setopt()参数警告

<div class="post-text" itemprop="text"> <p>Tried to send the post request with XML body using CURL but constantly getting following error,</p> <pre><code>Warning: curl_setopt() expects parameter 2 to be long, string given </code></pre> <p>I'm using following CURL request,</p> <pre><code>$ch = curl_init(POST_URL); curl_setopt($ch, CURLOPT_MUTE, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); </code></pre> </div>


对接百度小程序支付,回调的时候请求是过来了,看日志是返回了403; 自己测试接口是正常的,使用postman和curl都测试过,没有问题. 环境是lnmp. 日志: - - [12/Jul/2019:19:05:50 +0800] "POST /baidu/index.php HTTP/1.1" 403 781 "-" "Apache-HttpClient/4.5.5 (Java/1.8.0_171)"

php curl 提交参数中文乱码问题

A站通过url形式POST数据注册B站,psot的中文,在B站是显示乱码的; 直接贴码: $name="黄飞鸿"; $password="123456"; $get_url = "".$name."&password=".$password $row=getToken($get_url); $obj=json_decode($row); function getToken($url){ $ch = curl_init(); $this_header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8"); curl_setopt($ch, CURLOPT_HTTPHEADER,$this_header); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); return curl_exec($ch); } 对方收到的name是乱码的;导致注册失败。 求大侠支招~

PHP使用curl_init post 提交json 外部服务器报错

[code=php]$serviceURL = ''; $ch = curl_init ( $serviceURL ); curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $strjson ); //全部数据使用HTTP协议的POST操作来发送 curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, false ); curl_setopt ( $ch, CURLOPT_HTTPHEADER, array ( 'Content-Type: application/json; charset=utf-8;', 'Content-Length: ' . strlen ( $strjson ) ) ); curl_setopt($ch,CURLOPT_POST,1); $result = curl_exec ( $ch ); $errorNo = curl_errno ( $ch ); echo $errorNo."<br>"; //错误号 输出0 echo "error:".curl_error($ch); echo $result."<br>"; //执行信息 报错 curl_close ( $ch );[/code] json字符串:{"ccode":"1234ew4" , "ddate":"2015-12-16", "ccuscode":"0100001", "cinvcode":"100101", "iquantity":"1", "address":"测试地址", "cmemo":"无", "cmaker":"demo", "cverifer":"demo", "dpredate":"2015-12-17", "imoney":"1"} 其中ccode是需要变化的,同一个插入不进去。 报错信息 [img=][/img] 由于是往第三方插入数据,所以没法改变上传的形式 ,只能上传json格式。 另外如果网页中输入 然后再输入字符串是可以返回字符串的。完了以后就想是不是传送协议问题,但是我传的又确实是 content-type 为json的数据 。求大神指教,只有12分全部送上


我在做一个CURL模拟请求,但是请求没有结果,但因curl_error,给的错误是这个:string(62) "Failed to connect to port 1: Connection refused" 请求的URL地址是这个: 我模拟的原网址: 是一个查询违章的网站,验证码我已经可以程序识别,现在就是CURL模拟提交,总是提示我上面那个错误,如果直接访问那个URL地址,页面提示不能跨域访问! 服务器端代码应该是用java写的,应该是设置了某些IP不能直接调用wzcxrs.action 这个action! 所以想请教吧内大神们,有没有办法成功模拟POST提交,并获得正确结果! 二楼是我模拟POST的CURL代码~~~~

如何将PHP cURL POST请求发送到URL,接收文件并提供给用户下载?

<div class="post-text" itemprop="text"> <p>There's a url that when I pass some POST parameters it gives me back a file to download. What's the best way to make my server download that file and, while it downloads it sends to the user?</p> <p>Thanks in advance</p> </div>


<div class="post-text" itemprop="text"> <p>Hi I'm trying to validate a form using a json output tha I get from a cURL request. In my code I first check if the fields are empty or not, then I send the cURL request and I get the following json output if the fields are wrong</p> <pre><code>array(2) { ["errorDetailCode"]=&gt; int(-44) ["errorDetailMessage"]=&gt; string(37) "username or password not found" } array(2) { ["errorDetailCode"]=&gt; int(-2) ["errorDetailMessage"]=&gt; string(23) "username not found" } array(2) { ["errorDetailCode"]=&gt; int(-1) ["errorDetailMessage"]=&gt; string(19) "password not found" } </code></pre> <p>The problem is after it shows the first message username and password not found then it doesn't show the other two messages: username not foundand password not found but still show the message: username or password not found. Do you know why? Ths is my code</p> <pre><code>$km_username = filter_var($_POST['userName'], FILTER_SANITIZE_STRING); $km_user_password = $_POST['userPassword']; // Validate form fields if they are empty if(empty($km_username) &amp;&amp; empty($km_user_password)) { // Error message if email and password fields are empty $_SESSION['km_error_message'] = 'Insert username and password!'; header('Location: '.KM_BASE_URL.'/login.php'); exit(); }else if(empty($km_username)) { // Error message if username field is empty $_SESSION['km_error_message'] = 'Insert username!'; header('Location: '.KM_BASE_URL.'/login.php'); exit(); }else if(empty($km_user_password)) { // Error message if password field is empty $_SESSION['km_error_message'] = 'Insert password!'; header('Location: '.KM_BASE_URL.'/login.php'); exit(); } // Store form fields into an array $fields = array( 'userid' =&gt; $km_username, 'password' =&gt; $km_user_password ); // cURL request to API $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, URL_LOGIN_API); curl_setopt($cURL, CURLOPT_POST, 1); curl_setopt($cURL, CURLOPT_POSTFIELDS, http_build_query($fields)); curl_setopt($cURL, CURLOPT_HEADER, 0); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, TRUE); $cURL_response = curl_exec($cURL); // execute the curl command if (curl_error($cURL)) { echo curl_error($cURL); } curl_close ($cURL); $json_response = json_decode($cURL_response, true); // Form validation after cURL request if(isset($json_response['errorDetailCode'])){ // Error message if cURL request error $_SESSION['km_error_message'] = $json_response['errorDetailMessage']; header('Location: '.KM_BASE_URL.'/login.php'); exit(); }else{ // Store the cookie file name into the session if (!isset($_SESSION['cookiefile'])) { $cookiefile = tempnam(".", "cookie"); $_SESSION['cookiefile'] = basename($cookiefile); file_put_contents($cookiefile, ""); } // cURL request to API $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, URL_LOGIN_API); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); // Cookie aware curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); // Cookie aware $content = curl_exec($ch); curl_close($ch); // Redirerct user to dashboard header('Location: '.KM_BASE_URL.'/client-dashboard.php'); exit(); } </code></pre> </div>









立方体线框模型透视投影 (计算机图形学实验)

计算机图形学实验 立方体线框模型透视投影 的可执行文件,亲测可运行,若需报告可以联系我,期待和各位交流

2019 AI开发者大会

2019 AI开发者大会




一 专题从基础的C语言核心到c++ 和stl完成基础强化; 二 再到数据结构,设计模式完成专业计算机技能强化; 三 通过跨平台网络编程,linux编程,qt界面编程,mfc编程,windows编程,c++与lua联合编程来完成应用强化 四 最后通过基于ffmpeg的音视频播放器,直播推流,屏幕录像,










Linux常用命令大全(非常全!!!) 最近都在和Linux打交道,感觉还不错。我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较短小但却功能强大。我将我了解到的命令列举一下,仅供大家参考: 系统信息 arch 显示机器的处理器架构 uname -m 显示机器的处理器架构 uname -r 显示正在使用的内核版本 d...




深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

fakeLocation13.5.1 虚拟定位 ios13.5.1的最新驱动下载,iPhone/iPad免越狱虚拟定位工具Location-cleaned驱动已更新









【数据结构与算法综合实验】欢乐连连看(C++ & MFC)案例

这是武汉理工大学计算机学院数据结构与算法综合实验课程的第三次项目:欢乐连连看(C++ & MFC)迭代开发代码。运行环境:VS2017。已经实现功能:开始游戏、消子、判断胜负、提示、重排、计时、帮助。


学生成绩管理系统,分三个模块:学生,教师和管理员。 管理员模块:负责学生、老师信息的增删改;发布课程信息的增删改,以便让学生选课;审核老师提交的学生成绩并且打印成绩存档;按照课号查询每个课号的学生成绩




在中国清朝,明黄色的衣服只有皇子才有资格穿,慢慢的黄色在中国就成了高贵的颜色。在人们的色彩印象中,黄色也表现为暂停。所以当你的网页设计采用黄色的时候,会让人们在你的网页前停留。 黄色,就像橙色和红色,黄色也是一个暖色。它有大自然、阳光、春天的涵义,而且通常被认为是一个快乐和有希望的色彩。黄色是所有色相中最能发光的颜色,给人轻快,透明,辉煌,充满希望的色彩印象。 黄色是一个高可见的色...





学生成绩管理系统(PHP + MYSQL)

做的是数据库课程设计,使用的php + MySQL,本来是黄金搭配也就没啥说的,推荐使用wamp服务器,里面有详细的使用说明,带有界面的啊!呵呵 不行的话,可以给我留言!







相关热词 c#跨线程停止timer c#批量写入sql数据库 c# 自动安装浏览器 c#语言基础考试题 c# 偏移量打印是什么 c# 绘制曲线图 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行