Home  >  Article  >  Backend Development  >  php-PHP使用curl_init post 提交json 或 SoapClient 外部服务器报错

php-PHP使用curl_init post 提交json 或 SoapClient 外部服务器报错

WBOY
WBOYOriginal
2016-06-02 11:29:041149browse

phpcurljson

使用curl_init:

$serviceURL = 'http://61.153.225.106:5678/Service.asmx/tests';
$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; //错误号 输出0
echo "error:".curl_error($ch);
echo $result; //执行信息 报错
curl_close ( $ch );

<code></code>

使用 SoapClient :

$client = new SoapClient("http://61.153.225.106:5678/Service.asmx?WSDL", array('cache_wsdl' => 0));
$strjson = array('param1'=>'01', 'param2'=>'02');
$result = $client->__Call("tests", array( $strjson ));

图片说明

<code></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是需要变化的,同一个插入不进去。
由于是往第三方插入数据,所以没法改变上传的形式 ,只能上传json格式。
另外如果网页中输入 http://61.153.225.106:5678/Service.asmx?op=tests 然后再输入字符串是可以返回字符串的。
后面这个SoapClient方法并不能返回程序执行的数据,求解,两种无论使用哪一种都行,只要能通过就可以了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn