发送短信时使用php-cURL进行cURL请求时出错 [英] Error on cURL request using php-cURL while sending SMS

查看:99
本文介绍了发送短信时使用php-cURL进行cURL请求时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


此资源不支持请求实体的媒体类型'multipart / form-data'
。\,\ ExceptionMessage\不确定表情 No
MediaTypeFormatter可用于从媒体类型为
'multipart / form-data'的内容中读取类型为'SmsQueue'
的对象。\,\ ExceptionType\不确定
表情符号 System.Net.Http.UnsupportedMediaTypeException, StackTrace不确定
表情符位于
System.Net.Http.HttpContentExtensions.ReadAsAsync [T](HttpContent
内容,类型类型,IEnumerable 1格式化程序,IFormatterLogger
formatterLogger,CancellationToken cancelleToken)在
处运行System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage
请求,类型类型,IEnumerable`1格式化程序,IFormatterLogger
formatterLogger,CancellationToken cancelToken)\}

The request entity's media type 'multipart/form-data' is not supported for this resource.\",\"ExceptionMessage\"unsure emoticon"No MediaTypeFormatter is available to read an object of type 'SmsQueue' from content with media type 'multipart/form-data'.\",\"ExceptionType\"unsure emoticon"System.Net.Http.UnsupportedMediaTypeException\",\"StackTrace\"unsure emoticon" at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable 1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\"}"



    // Prepare you post parameters
    $postArray = array(
        'APIKey' => AUTH_KEY,
        'number' => $mobile,
        'text' => $message,
        'senderid' => SENDER_ID,
        'channel' => $channel,
        'DCS' => $DCS,
        'flashsms' => $flashsms,
        'route' => $route
    );

    // Init the resource
    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $postArray
    ));

    // Ignore SSL certificate verification
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    // Get response
    $curlOutput = curl_exec($ch);

    // Print error if any
    if (curl_errno($ch)) {
        echo 'error:' . curl_error($ch);
    }

    curl_close($ch);


推荐答案

将标头中的Content-Type设置为application / x- www-form-urlencoded。
像这样使用:

Set Content-Type in header to application/x-www-form-urlencoded. Use like this :

        $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => "http://url.com",
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => http_build_query(['message' => test]),
        CURLOPT_HTTPHEADER => array(
            'Content-Type: application/x-www-form-urlencoded'
        ),
    ));

这篇关于发送短信时使用php-cURL进行cURL请求时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆