http协议jsonphpcurl
[code=php]$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]
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=http://img.bbs.csdn.net/upload/201512/18/1450420302_248471.jpg][/img]
由于是往第三方插入数据,所以没法改变上传的形式 ,只能上传json格式。
另外如果网页中输入 http://61.153.225.106:5678/Service.asmx/tests 然后再输入字符串是可以返回字符串的。完了以后就想是不是传送协议问题,但是我传的又确实是 content-type 为json的数据 。求大神指教,只有12分全部送上
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号