Php Symfony2 Guzzle设置HTTP请求
我在Symfony2中工作,我尝试在我的一个测试(PHPUnit)中使用Guzzle在我的请求中设置一些值 我想在我的请求中添加以下内容:Php Symfony2 Guzzle设置HTTP请求,php,symfony,Php,Symfony,我在Symfony2中工作,我尝试在我的一个测试(PHPUnit)中使用Guzzle在我的请求中设置一些值 我想在我的请求中添加以下内容: $string = '{ "postcode":"XXX-XXX", "source_channel":"BU", "flow":"ENQUIRY", "email_address":"test@test", "first_name":"
$string = '{
"postcode":"XXX-XXX",
"source_channel":"BU",
"flow":"ENQUIRY",
"email_address":"test@test",
"first_name":"Bob",
"surname":"White",
"User-Agent":"Mozilla",
}';
我的狂饮代码:
$client = new \Guzzle\Http\Client();
$post = $client->post('http://127.0.0.1/api/save/details', array(), $string);
$data = $post->send();
错误:
Guzzle\Http\Exception\ClientErrorResponseException: Client error response
[status code] 404
[reason phrase] Not Found
[url] http://127.0.0.1/api/save/details
我真的是一个新手,但这似乎是直截了当地在我试图做什么。我从错误信息中推测可能是错误的,但URL有问题,事实上我知道这是好的
你知道这里可能出了什么问题吗?在我看来,你的url的域部分有一个输入错误。尝试改变
'http://127.0.0.1:/api/save/details'
到
很好,但这不是我忘记删除的问题:因为我试图使用不同的por来查看它是否像:8000使用浏览器时,您的操作是否有效?您是否尝试访问
http://127.0.0.1/api/save/details
在您的浏览器中?是的,它在我的浏览器中工作
'http://127.0.0.1/api/save/details'