PHP获取HTTP 400响应的内容 [英] PHP Get Content of HTTP 400 Response

查看:121
本文介绍了PHP获取HTTP 400响应的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP与Amazon Payments网络服务。我有一些我的请求的问题。亚马逊返回一个错误,因为它应该,但它的方式是给我的问题。

I am using PHP with the Amazon Payments web service. I'm having problems with some of my requests. Amazon is returning an error as it should, however the way it goes about it is giving me problems.

亚马逊返回XML数据与错误的消息,但它也抛出一个HTTP 400(甚至404)。这使得file_get_contents()立即抛出一个错误,我没有办法获取内容。我已经尝试使用cURL,但从来没有给我回来一个响应。

Amazon returns XML data with a message about the error, but it also throws an HTTP 400 (or even 404 sometimes). This makes file_get_contents() throw an error right away and I have no way to get the content. I've tried using cURL also, but never got it to give me back a response.

我真的需要一种方式来获取返回的XML,不管HTTP状态代码。它有一个重要的消息元素,它提供了我为什么我的结算请求失败的线索。

I really need a way to get the XML returned regardless of HTTP status code. It has an important "message" element that gives me clues as to why my billing requests are failing.

有没有人有一个cURL示例或其他将允许我做这个?我所有的请求目前使用file_get_contents(),但我不反对改变它们。

Does anyone have a cURL example or otherwise that will allow me to do this? All my requests currently use file_get_contents() but I am not opposed to changing them. Everyone else seems to think cURL is the "right" way.

推荐答案

你必须定义自定义流上下文file_get_contents)和 ignore_errors 选项。

You have to define custom stream context (3rd argument of function file_get_contents) with ignore_errors option on.

这篇关于PHP获取HTTP 400响应的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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