显示内容类型text/html而不是application/Json的Json响应
我正在使用Postman chrome扩展发送帖子并获取请求和响应 我得到以下回应-显示内容类型text/html而不是application/Json的Json响应,json,http-headers,Json,Http Headers,我正在使用Postman chrome扩展发送帖子并获取请求和响应 我得到以下回应- { "Myresponse": { "ResponseStatus": 1, "PhoneCount": 3, "Page": "1", "PageSize": "3", "Phones": { "Phone": [ { "AccountSid": "5fd7e139-080c-49ab-bbe4-7c9f686dc64e", "PhoneSid":
{
"Myresponse": {
"ResponseStatus": 1,
"PhoneCount": 3,
"Page": "1",
"PageSize": "3",
"Phones": {
"Phone": [
{
"AccountSid": "5fd7e139-080c-49ab-bbe4-7c9f686dc64e",
"PhoneSid": "5c993989-d8cd-496b-b83c-160023247097",
"FriendlyName": "2013554746",
"PhoneNumber": "2013554746",
"VoiceUrl": null,
"VoiceMethod": null,
"VoiceFallbackUrl": "",
"VoiceFallbackMethod": null,
"DateCreated": "2016-04-08 02:27:52",
"SMSRequestUrl": null,
"SMSMethod": null,
"SMSFallbackUrl": null,
"SMSFallbackMethod": null,
"HeartbeatUrl": "",
"HeartbeatMethod": null,
"HangupCallback": "",
"HangupCallbackMethod": null,
"VoiceEnable": "",
"SmsEnable": "true",
"ApiVersion": "2"
},
{
"AccountSid": "5fd7e139-080c-49ab-bbe4-7c9f686dc64e",
"PhoneSid": "a3b88f36-62d7-49d1-b138-7d6d6c5950b2",
"FriendlyName": "2014271285",
"PhoneNumber": "2014271285",
"VoiceUrl": null,
"VoiceMethod": null,
"VoiceFallbackUrl": "",
"VoiceFallbackMethod": null,
"DateCreated": "2016-04-08 02:27:52",
"SMSRequestUrl": null,
"SMSMethod": null,
"SMSFallbackUrl": null,
"SMSFallbackMethod": null,
"HeartbeatUrl": "",
"HeartbeatMethod": null,
"HangupCallback": "",
"HangupCallbackMethod": null,
"VoiceEnable": "",
"SmsEnable": "true",
"ApiVersion": "2"
},
{
"AccountSid": "5fd7e139-080c-49ab-bbe4-7c9f686dc64e",
"PhoneSid": "670f91f5-b460-4b3b-a0d1-35e742c2a5ef",
"FriendlyName": "2014271285",
"PhoneNumber": "2014271285",
"VoiceUrl": "https://76bvuptovu4g.runscope.net",
"VoiceMethod": "GET",
"VoiceFallbackUrl": "http://voicefallback.com",
"VoiceFallbackMethod": "GET",
"DateCreated": "2016-04-08 02:22:41",
"SMSRequestUrl": "https://g62ou2lugq56.runscope.net",
"SMSMethod": "GET",
"SMSFallbackUrl": "https://g62ou2lugq56.runscope.net",
"SMSFallbackMethod": "GET",
"HeartbeatUrl": "",
"HeartbeatMethod": "GET",
"HangupCallback": "",
"HangupCallbackMethod": "GET",
"VoiceEnable": "true",
"SmsEnable": "true",
"ApiVersion": "2"
}
]
}
}
}
及
当我检查响应的内容类型时,第一个是给出的application/json,第二个是给出的text/html
有什么不对劲吗?谁能帮我一下吗?任何帮助都将不胜感激。如果您得到响应类型。请尝试下面的代码
在返回响应之前添加此选项
// Set header content
if($this->requestType == 'xml'){
$this->header('Content-Type', "application/xml; charset=UTF-8");
}else{
$this->header('Content-Type', "application/json; charset=UTF-8");
}
试试这个,希望对你有帮助
header("Content-Type: application/json; charset=UTF-8");
header("Content-Type: application/json; charset=UTF-8");