dongnius85154 2014-01-10 20:02
浏览 110
已采纳

卷曲请求什么都不返回

I'm trying to send request my api from curl using ajax call but it's not working.

<!-- MY FUNCTION that PERFORMs CURL REQUEST (This function is GETTING CALLED FROM ANOTHER FUNCTION THATS BEEN CALLED BY MY AJAX REQUEST)-->>

$ch = curl_init('http://myurl/add.json');
            curl_setopt($ch, CURLINFO_HEADER_OUT, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST); 
            if(!is_null($jsonString)) { //if json strng isn't null
               curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);  
            }       
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
                'Content-Type: application/json',                                                                                
                'Content-Length: ' . strlen($jsonString),
                'signedInUserId: ' . USERID,
                'accessToken: ' . TOKEN)                                                                       
            );  
            $result = curl_exec($ch);
            curl_close($ch);

The problem here is I'm getting nothing in $result. Seems like curl request isn't working.

Can anyone tell me, what m I missing ? My site is hosted on amazon ec2 (ubuntu 13.10).

  • 写回答

1条回答 默认 最新

  • dqc42632 2014-01-11 11:52
    关注

    Thank you very much for your interest to help. There was a weird issue. I had space in

        curl_init('myurl/add.json '); 
    

    Although I have same code on two different ec2 instances (servers) one is working the other isn't. $result had "". I just removed the space and run. and the other server started working too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch