is debug using the POSTMAN
tool, the raw
data submitted in the form will return to the bottom of the string of data;
Instead, the form-urlencoded
data that was submitted in the form of the file is returned with an error. The same is true with the 1th form-data
form.
Now the situation is that I'm PHP
using curl
the post
same error as the data that is shown.
The code is as follows:
function curls($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-AjaxPro-Method:ShowList', 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data_string)) ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); $data = curl_exec($ch); curl_close($ch); return $data;} $get_url = "http://abc.xxx.com/UC_News_ShowList,App_Web_abc.ashx"; $post_str = '{"P":5,"Sclass":"新闻","Table":"HS_N_News","Link":"News"}'; $post_datas = curls($get_url, $post_str); echo $post_datas;
?>
Evil Split Line: Resolved
Resolved:
This has nothing to do with the Post method. It's because there's a missing header.
$headers = array( "User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36", "X-AjaxPro-Method:ShowList" );
The final pattern of the code is:
function curls($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-AjaxPro-Method:ShowList', 'User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36' ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); $data = curl_exec($ch); curl_close($ch); return $data;} $get_url = "http://abc.xxx.com/UC_News_ShowList,App_Web_abc.ashx"; $post_str = '{"P":5,"Sclass":"新闻","Table":"HS_N_News","Link":"News"}'; $post_datas = curls($get_url, $post_str); echo $post_datas;
POST
Data is still in the json
format of the data, not array
the form. POSTMAN
It's been given to a hole ~!!!
Reply content:
is debug using the POSTMAN
tool, the raw
data submitted in the form will return to the bottom of the string of data;
Instead, the form-urlencoded
data that was submitted in the form of the file is returned with an error. The same is true with the 1th form-data
form.
Now the situation is that I'm PHP
using curl
the post
same error as the data that is shown.
The code is as follows:
function curls($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-AjaxPro-Method:ShowList', 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data_string)) ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); $data = curl_exec($ch); curl_close($ch); return $data;} $get_url = "http://abc.xxx.com/UC_News_ShowList,App_Web_abc.ashx"; $post_str = '{"P":5,"Sclass":"新闻","Table":"HS_N_News","Link":"News"}'; $post_datas = curls($get_url, $post_str); echo $post_datas;
?>
Evil Split Line: Resolved
Resolved:
This has nothing to do with the Post method. It's because there's a missing header.
$headers = array( "User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36", "X-AjaxPro-Method:ShowList" );
The final pattern of the code is:
function curls($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-AjaxPro-Method:ShowList', 'User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36' ); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); $data = curl_exec($ch); curl_close($ch); return $data;} $get_url = "http://abc.xxx.com/UC_News_ShowList,App_Web_abc.ashx"; $post_str = '{"P":5,"Sclass":"新闻","Table":"HS_N_News","Link":"News"}'; $post_datas = curls($get_url, $post_str); echo $post_datas;
POST
Data is still in the json
format of the data, not array
the form. POSTMAN
It's been given to a hole ~!!!
http://stackoverflow.com/questions/13099177/how-to-send-raw-post-data-with-curl-php
It is said to set an unrecognized Content-Type
, postfileds or pass an array as before.
Raw is the most primitive data in the HTTP request entity content body, you can customize the body data sent to the server, and set the header to determine the type of body for the server to resolve. If you do not set Content-type, the default is x-www-form-urlencoded. Body in the form of parameter =& parameter =
curl_setopt($handle, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
has been resolved, thank you.