Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Sendhub api问题_Php_Javascript_Json - Fatal编程技术网

Php Sendhub api问题

Php Sendhub api问题,php,javascript,json,Php,Javascript,Json,我正在使用SendhubAPI 并且得到了这个错误 所示格式“application/x-www-form-urlencoded”没有可用的反序列化方法。请检查序列化程序上的格式和内容类型 我使用的代码是: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, "Content-Type: appli

我正在使用SendhubAPI

并且得到了这个错误

所示格式“application/x-www-form-urlencoded”没有可用的反序列化方法。请检查序列化程序上的
格式
内容类型

我使用的代码是:

    $ch = curl_init();

                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/json");
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

                if(LOCAL_MODE){
                  curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
                  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
                  curl_setopt($ch, CURLOPT_PROXY, FALSE);
                 }

                curl_setopt($ch, CURLOPT_POST, 1);

                $data = '{
                   "contacts": [
                      1111
                   ],
                   "text": "Testing"
                }';

                curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
                echo $result=curl_exec ($ch);
                echo curl_error($ch);
有人能帮我解决这个问题吗


谢谢。

似乎未正确发送内容类型

消息“指示的格式为'application/x-www-form-urlencoded'没有可用的反序列化方法。”表示服务器正在将内容类型读取为'application/x-www-form-urlencoded'而不是'application/json'

您应该如下设置内容类型:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
(注意,CURLOPT_头现在是CURLOPT_HTTPHEADER)


假设您的url(包括用户名和apikey)是正确的,并且提供的联系人ID存在,现在应该可以工作了

似乎未正确发送内容类型

// The code
$vs_user = $t_user->getAppConfig()->get('sms_user');
$vs_api_key = $t_user->getAppConfig()->get('sms_api_key');
$vs_url = "https://api.sendhub.com/v1/messages/?username={$vs_user}&api_key={$vs_api_key}";
$o_ch = curl_init();
$ps_message = stripslashes(rawurldecode($ps_message));
$ps_message = trim(preg_replace("!\n+!","\\"."n", $ps_message));
curl_setopt($o_ch, CURLOPT_URL, $vs_url);
curl_setopt($o_ch, CURLOPT_HEADER, false);
curl_setopt($o_ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($o_ch, CURLOPT_POSTFIELDS, '{"contacts":['.$vn_sendhub_contact_id.'],"text":"'.$ps_message.'"}');
curl_setopt($o_ch, CURLOPT_RETURNTRANSFER, 1);
$vs_return = curl_exec($o_ch);
$va_return = json_decode($vs_return);
curl_close($o_ch); 
消息“指示的格式为'application/x-www-form-urlencoded'没有可用的反序列化方法。”表示服务器正在将内容类型读取为'application/x-www-form-urlencoded'而不是'application/json'

您应该如下设置内容类型:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
(注意,CURLOPT_头现在是CURLOPT_HTTPHEADER)

假设您的url(包括用户名和apikey)是正确的,并且提供的联系人ID存在,现在应该可以工作了

// The code
$vs_user = $t_user->getAppConfig()->get('sms_user');
$vs_api_key = $t_user->getAppConfig()->get('sms_api_key');
$vs_url = "https://api.sendhub.com/v1/messages/?username={$vs_user}&api_key={$vs_api_key}";
$o_ch = curl_init();
$ps_message = stripslashes(rawurldecode($ps_message));
$ps_message = trim(preg_replace("!\n+!","\\"."n", $ps_message));
curl_setopt($o_ch, CURLOPT_URL, $vs_url);
curl_setopt($o_ch, CURLOPT_HEADER, false);
curl_setopt($o_ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($o_ch, CURLOPT_POSTFIELDS, '{"contacts":['.$vn_sendhub_contact_id.'],"text":"'.$ps_message.'"}');
curl_setopt($o_ch, CURLOPT_RETURNTRANSFER, 1);
$vs_return = curl_exec($o_ch);
$va_return = json_decode($vs_return);
curl_close($o_ch); 
检查我使用的php


检查我的php,作为后续操作,我建议您使用curl和-vv参数来测试REST请求,这样您就可以确定线路上发生了什么。作为后续操作,我建议您使用curl和-vv参数来测试您的REST请求,这样您就可以确定发生了什么。嘿,sheeraz,您能帮我提供完整的url代码以及如何添加键和用户名吗?嘿,sheeraz,您能帮我提供完整的url代码以及如何添加键和用户名吗?