dongqiancui9194 2014-06-04 17:57
浏览 34

too long

I'm a little confused on how to set up a cURL request to an API I'm working with. To be specific, it's for a fulfillment center called ShipStation (http://api.shipstation.com). I've done many cURL requests in the past but now I'm trying to figure out how to set up a 'MERGE' cURL request as opposed to a 'GET' cURL request, etc. You can see on here the 'GET' header to pull info from the API:

http://api.shipstation.com/Order-Resource.ashx#Reading_an_Order_5

And then to update/merge data:

http://api.shipstation.com/Order-Resource.ashx#Updating_an_Order_6

Every time I try to send a request though, I get curl_setopt(): supplied argument is not a valid cURL handle resource errors on several lines. I tried initially by copying the data and trying to send it as a header:

$header .= "GET https://data.shipstation.com/1.3/Orders(128714) HTTP/1.1";
$header .= "User-Agent: Microsoft ADO.NET Data Services";
$header .= "Accept-Charset: UTF-8";
$header .= "DataServiceVersion: 1.0;NetFx";
$header .= "MaxDataServiceVersion: 2.0;NetFx";
$header .= "Accept: application/atom+xml,application/xml";
$header .= "Host: data.shipstation.com";

//Send request
$curlConn = curl_init(); 
curl_setopt($curlConn,CURLOPT_USERPWD,'myusername:mypassword'); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
curl_setopt($curlConn,CURLOPT_RETURNTRANSFER,1); 
$ret = curl_exec($curlConn); 
curl_close($curlConn);

I do update the username and password to my credentials since you need that to log into this API. I basically copied the header as it was and it doesn't work. I also updated 'CURLOPT_CUSTOMREQUEST' to 'CURLOPT_HTTPHEADER' but both gave errors.

I'm not understanding where I'm going wrong and I also don't know how (if it's possible) to return more detailed error messages so I can get to the bottom of the problem with the code since I just get the supplied argument error.

Thanks for your help!

EDIT

Perhaps I'm approaching this wrong? How would I send a 'MERGE' request as evidenced in the documentation in the links above. I don't know how to take that info that they've given (the header info) and translate it into a request to the API.

  • 写回答

2条回答 默认 最新

  • dtjpnd7517 2014-06-04 18:07
    关注

    Try in this way:

    $end = "
    ";  
    $header .= "GET https://data.shipstation.com/1.3/Orders(128714) HTTP/1.1" . $end;
    $header .= "User-Agent: Microsoft ADO.NET Data Services"  . $end;
    $header .= "Accept-Charset: UTF-8" . $end;
    $header .= "DataServiceVersion: 1.0;NetFx" . $end;
    $header .= "MaxDataServiceVersion: 2.0;NetFx" . $end;
    $header .= "Accept: application/atom+xml,application/xml" . $end;
    $header .= "Host: data.shipstation.com" . $end;
    
    //Send request
    $curlConn = curl_init(); 
    curl_setopt($curlConn,CURLOPT_USERPWD,'myusername:mypassword'); 
    curl_setopt($curlConn, CURLOPT_CUSTOMREQUEST, $header);
    curl_setopt($curlConn,CURLOPT_RETURNTRANSFER,1); 
    $ret = curl_exec($curlConn); 
    curl_close($curlConn);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办