문제

I'm using the PEAR library Http_Request2. I've been unsuccessfully searching for documentation on how to make a PUT request and pass parameters to a webservice. Can anyone provide some help?

For a POST request, it's easy:

 $request = new HTTP_Request2 ( "http://my.url.com");
 $request->setMethod(HTTP_Request2::METHOD_POST);
 $request->addPostParameter('data', "blah"); //easy to add post params...
 $response = $request->send();

However, I can't figure how to send data when changing the method to PUT:

 $request = new HTTP_Request2 ( "http://my.url.com");
 $request->setMethod(HTTP_Request2::METHOD_PUT);

 // ?????  missing secret sauce to add data to put request....

 $response = $request->send();

Anyone lend a hand?

도움이 되었습니까?

해결책

You need to use setBody() to set your PUT data. Don't forget the header, e.g.

$request->setHeader('Content-type: application/json');
$request->setBody('{"foo":"bar"}');
$response = $request->send();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top