Am I using the Yfrog API correctly to make an HTTP request with POST data?

I am trying to use the YFrog API. I think I'm using it correctly to try and send an HTTP POST request with XML content type. However, as a response body, I always get a 404 error for some reason. Here is their API: http://yfrog.com/upload_and_post.php

Here is my attempt at loading PHP code.

 $data = array('media' => 'http://img253.imageshack.us/my.php?image=bfab82a545d414uo.jpg', 'username' => 'asc', 
    'password' => 'asc', 'message' => 'hi');

$url = 'http://yfrog.com/api/uploadAndPost';

$req = new HTTPRequest($url);
$req->addHeaders(array("Content-Type" => "text/xml")); 
$req->setMethod(HTTP_METH_POST); 
$req->addQueryData($data); $req->send();
echo $req->getResponseBody();

      

Also for the media, does this mean "binary image data" means the URL of the image location cannot be passed to it? What does it mean?

Thanks for any help?

+1


source to share


3 answers


I think the problem is that ImageHack does not return the binary when you specify the URL posted above. For me, it returns an HTML document.

I think you should try passing the binary as the "media" parameter. The photo you are trying to get is at http://img253.imageshack.us/img253/172/bfab82a545d414uo.jpg , use this url instead.



This is the answer I get with the one you originally tried:

HEAD /my.php?image=bfab82a545d414uo.jpg HTTP/1.1
Host: img253.imageshack.us

HTTP/1.1 200 OK
X-Powered-By: PHP/5.2.6
Set-Cookie: nopopunder=1; expires=Thu, 07-May-2009 11:10:21 GMT; path=/; domain=.imageshack.us
X-UA-Compatible: IE=EmulateIE7
Content-type: text/html

      

+1


source


You need to use addPostFields and addPostFile instead of addQueryData. An example of using both is here



@MC is correct in that you cannot send a url pointer to a file somewhere else, you really need to download those bytes. Therefore, you will first want to download a local copy by passing the path to your local copy of that file to the addPostFile method.

0


source


You need to use Content-Type

multipart/form-data

.

yfrog sends back an XML file as a response, but the API expects a standard HTTP POST request with image data.

API docs :

"data should be formatted as multipart / form-data"

0


source







All Articles