Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

请教一个php新手才可能遇到的问题:使用curl进行post请求结果后面多个1

如题;使用php的curl发送post请求;数据可以拿到,但是在服务端返回的json字符串上多了一个数字1,查代码也没找到是什么时候被添加上的,百度完全找不到这方面的资料,应该只有我这样的新手才会遇到吧;

机密原因请求接口不能发出来,代码如下:

<?php
$url = "域名:9789/接口";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url); 
  curl_setopt($ch, CURLOPT_POST,1); 
  curl_setopt($ch, CURLOPT_POSTFIELDS, "goodsId=56");
  $rt = curl_exec($ch);
  curl_close($ch);
  echo $rt;

页面输出:

{"model":{"id":1},"onTop":2,"soldCount":0,"result":0,"timeMillis":1492765168804}1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

加上这个
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

具体意义自己搜索


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...