【问题标题】:Call to endpoint fails returns string(69) "Error: This method supports only xml ExceptionType: System.Exception"调用端点失败返回字符串(69)“错误:此方法仅支持 xml ExceptionType:System.Exception”
【发布时间】:2020-11-27 19:23:02
【问题描述】:

我正在尝试使此代码在端点返回数据,但它返回此错误string(69) "Error: This method supports only XML ExceptionType: System. Exception"。我试过检查它的含义,但无法弄清楚。

代码分为两部分,第一部分转储$result 数组变量运行良好。 $resResult 的第二个转储是问题所在。这意味着调用第一个端点运行良好,但调用第二个端点一直失败。

代码 PHP

$username = '73ec71d0a809/Markettrendsintl';
$password = 'Market@123';
$surveyID = '47f2-bfe4-db0eb01d1049';
$endpoint = 'https://api.dooblo.net/newapi/SurveyInterviewIDs?surveyIDs='.$surveyID;

$credentials = base64_encode("$username:$password");

$headers = [];
$headers[] = "Authorization: Basic {$credentials}";
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'Cache-Control: no-cache';

$headers1 = [];
$headers1[] = "Authorization: Basic {$credentials}";
$headers1[] = 'Content-Type: text/xml';
$headers1[] = 'Cache-Control: no-cache';


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result[] = curl_exec($ch);

/*---------New Code -----------------*/
$counter = 0;
$interviewIdsInCurPack = '';
for ($i=0; $i < count($result); $i++) { 
  $interviewIdsInCurPack = sprintf("{0},{1}", $interviewIdsInCurPack, $result[$i]);
  $counter += 1;
  $lastInterviewID = $i==$result[$i];

  if ($counter == 99 || $lastInterviewID) {
      $interviewIdsInCurPack = substr_replace($interviewIdsInCurPack, 0, 1);
                 $urlInterviewData = sprintf("https://api.dooblo.net/newapi/SurveyInterviewData?subjectIDs={0}&surveyID={1}&onlyHeaders=false&includeNulls=false", $interviewIdsInCurPack, $surveyID);
                 // print($urlInterviewData);

                  $sender = curl_init();

                  curl_setopt($sender, CURLOPT_URL, $urlInterviewData);
                  curl_setopt($sender, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($sender, CURLOPT_CUSTOMREQUEST, 'GET');
                  curl_setopt($sender, CURLOPT_HTTPHEADER, $headers1);

                  $resResult = curl_exec($sender);
                   var_dump($resResult);
  }
}

【问题讨论】:

    标签: php curl endpoint surveytogo


    【解决方案1】:

    根据Dooblo的documentation

    但是,请记住,对于某些返回采访数据或调查数据的操作,仅支持 XML 作为输出格式。如果您尝试使用 JSON 作为格式调用这些,您将收到错误:来自 API 的“错误:此方法仅支持 xml”

    最后一部分正是您的错误消息。根据他们的REST API example 代码,您可以使用HTTP Accept header 设置所需的输出格式:

    client.AddDefaultHeader("Accept", "text/xml");

    client.AddDefaultHeader("Accept-Charset", "utf-8");

    他们在那里使用不同的客户端,在 PHP 中您可以按如下方式进行操作:

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept: text/html',
        'Accept-Charset: utf-8'
    ));
    

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 1970-01-01
      • 2017-02-26
      • 2014-08-05
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      相关资源
      最近更新 更多