CURL返回完整的字符串响应而不是xml

时间:2017-04-07 08:39:17

标签: php xml curl

我试图在PHP中使用CURL来提取数据

val distinctValues = hiveContext.sql("select KEY from BigTbl").distinct().count() // find count distinct values 

hiveContext.sql("select * from BigTbl DISTRIBUTE by KEY")
       .repartition(distinctValues.toInt) // repartition to number of distinct values
       .registerTempTable("NewBigTbl") // register the repartitioned table as another temp table

hiveContext.cacheTable("NewBigTbl") // cache the repartitioned table for improving query performance

但是当响应应该是xml格式时,我得到完整字符串的响应,当我打印响应变量的类型时,它打印字符串。我尝试使用Postman来检查响应,并在XML模式下返回正确的格式:

xml format

当我在Postman中更改为预览模式时,它显示的结果与我在php中的CURL响应显示的结果相同,即完整字符串:

string format

1 个答案:

答案 0 :(得分:2)

最有可能的是,您获得了正确的回复,只是您的浏览器无法按照您的预期进行呈现。如果在代码顶部添加header("content-type: text/plain;charset=utf8");,会发生什么?我的猜测,它会以你期望的方式呈现代码。或者,html对其进行编码,例如

function hhb_tohtml(string $str):string
{
    return htmlentities($str, ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED, 'UTF-8', true);
}
print_r(hhb_tohtml($return));
print_r(gettype($return)); //prints string