Php POST - get boundary value - php

So I want to upload a file using curl, but the problem is: the post request contains a boundary variable that is checked upon by the website. I know this because I get errors when modifying this variable in Tamper Data.
Http headers (important part):
Content-Type: multipart/form-data; boundary=----pluploadboundaryp18mu3sf5fus08pd11c3kvq163514
Post request:
------pluploadboundaryp18mu3sf5fus08pd11c3kvq163514\r\n
Content-Disposition: form-data; name="name"\r\n
\r\n
1.jpg\r\n
------pluploadboundaryp18mu3sf5fus08pd11c3kvq163514\r\n
Content-Disposition: form-data; name="imageData"; filename="1.jpg"\r\n
Content-Type: image/jpeg\r\n
\r\n
{Filecontent}
So my question is: How can I bypass or duplicate this boundary?
Edit: if you want to test yourself the form upload is located at:https://www.marktplaats.nl/syi/239/1399/plaatsAdvertentie.html

So i got the answer on my question. Also thanks to Ruslan Bes for helping.
The problem was i sended my post request as http_build_query($post) instead of $post.
Small mistakes can cause a lot of problems :D

Related

how to read data sent from post Content-Type: multipart/form-data; boundary=

can you guy's help me with this plz
i have data sent from post Content-Type: multipart/form-data; boundary=
-poster.php is sending post
-reciver.php is the file im posting to
--------------------------42281d81075fd0d5
Content-Disposition: form-data; name="one"
this is one
--------------------------42281d81075fd0d5
Content-Disposition: form-data; name="two"
this is two
--------------------------42281d81075fd0d5--
so what i want to know is how i can get those values
i dont think $_POST[''];
i can't figur it out
thank you for your help
You can access the values by $_POST['one'] and $_POST['two'] in case of normal form data.
If you want to read a file that you uploaded you can access this by using $_FILES['name_of_file_input_field'].
when you using some php framework and jQuery then you receiving your data like that. You might jQuery ajax setting with contentType set to false. Then you can get the data like you want.

php curl send multiple data under one key

How to send data via curl which is under select tag? I can't find answer, please help, browser's procedure as follows:
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryEbHiNmjjU3pgp1Tb
------WebKitFormBoundaryEbHiNmjjU3pgp1Tb
Content-Disposition: form-data; name="allVolumeCountries"
6
------WebKitFormBoundaryEbHiNmjjU3pgp1Tb
Content-Disposition: form-data; name="allVolumeCountries"
13
P.S: I don't have access to source, so don't advise me to change to something like allVolumeCountries[]

POST request with files and fields in guzzle

Ok I'll give a little background to start. I have system A written in CakePHP that handles ads and products and such. Recently I have been working on another system, written in Laravel, that acts as a self-serve tool for realtors to post and manage their real estate listings that reside in system A. I am now at the point of uploading images from the self-serve site to system A. I wrote a simple controller action in Cake to handle a POST request and save the image file on the server.
http://example.com/image/add
I am able to send POST requests, upload images and get a proper response using REST applications such as postman. All looks good on system A (Cake) side of things.
Now in the self-serve system, in Laravel, I am using Guzzle to send HTTP requests. I have filled out the guzzle post request with the exact same fields and files, but I don't recieve the same output. The request is received by system A, but the image is not added and a random HTML page is returned. If postman and a few other applications get the exact same response and functionality, but my request sent in Guzzle is not, I am thinking there is an issue with my guzzle request. Here is my guzzle code:
$client = new Client();
// Create the request.
$request = $client->createRequest("POST", "http://example.com/image/add");
// Set the POST information.
$postBody = $request->getBody();
$postBody->setField('user_id', $userId);
$postBody->setField('api_key', $token);
$postBody->setField('product_id', $product_id);
$postBody->addFile(new PostFile('image[data]', fopen('tmp/images/'.$input->image, 'r')));
// Send the request and get the response.
$response = $client->send($request);
Here is the working POST request from Postman:
POST /image/add HTTP/1.1
Host: example.com
Cache-Control: no-cache
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="product_id"
1000
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="user_id"
8345
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="api_key"
secretKey
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="data[image]"; filename="steve-jobs.jpg"
Content-Type: image/jpeg
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Here is the guzzle request to string, I apologize for readability issues.
POST /image/add HTTP/1.1 Host: example.com User-Agent: Guzzle/4.0.2 curl/7.22.0 PHP/5.5.9-1+sury.org~precise+1 Content-Length: 124647 Content-Type: multipart/form-data; boundary=53a1f21e04080 --53a1f21e04080 Content-Disposition: form-data; name="user_id" 8345 --53a1f21e04080 Content-Disposition: form-data; name="api_key" secretKey --53a1f21e04080 Content-Disposition: form-data; name="product_id" 1000 --53a1f21e04080 Content-Disposition: form-data; filename="steve-jobs.jpg"; name="image[data]" Content-Type: image/jpeg
Then a bunch a characters for the image data.
I am asking if anyone can see an issue with my POST request in guzzle or if anyone has run into this kind of weird issue with guzzle before.
Edit:
I am using CakePHP 2.4.1
As far as I can tell it's just a small mistake in the file field name, it should be data[image], not image[data].
new PostFile('data[image]', /* ... */);
In your app you are probably relying on the file data being available via CakeRequest::$data, however it will only land there in case it's wrapped in the data key, otherwise it is added to CakeRequest::$params['form'].
Not really a duplicate, however for (a more CakePHP form helper related) reference see also:
CakePHP: posted file data not included in request->data

Upload video via cURL

I am trying to upload some video name test.avi to dailymotion..
I used cURL to login to dailymotion, and than I am trying to upload a video through this url http://www.dailymotion.com/widget/upload?skin=default
I scanned the requests when uploading some example video.. but it only gives me this:
Request URL
http://www.dailymotion.com/widget/upload?skin=default&upload_id=c73413240d828de0ce987018dddcb6ed&sid=5444350aa8f801e2605f8f6de15ac38c&urlbase=http://www.dailymotion.com&flash_mode=1
Query String Parameters
skin:default
upload_id:c73413240d828de0ce987018dddcb6ed
sid:5444350aa8f801e2605f8f6de15ac38c
urlbase:http://www.dailymotion.com
flash_mode:1
Request Payload
------------gL6Ef1gL6KM7gL6ei4Ef1Ij5ae0ei4
Content-Disposition: form-data; name="Filename"
test.avi
------------gL6Ef1gL6KM7gL6ei4Ef1Ij5ae0ei4
Content-Disposition: form-data; name="Filedata"; filename="test.avi"
Content-Type: application/octet-stream
------------gL6Ef1gL6KM7gL6ei4Ef1Ij5ae0ei4
Content-Disposition: form-data; name="Upload"
Submit Query
------------gL6Ef1gL6KM7gL6ei4Ef1Ij5ae0ei4--
However, I am not quite sure what to do with this Payload Request.. Can anybody help me with this ?
That's a multi-part formpost, indeed possible to do with curl and its -F command line option. Just provide one -F for each input field in the form.
Of course, you may also need to actually login etc with curl first, and then you may also need to track cookies etc. If that sounds complicated, you may want to start reading on the curl HTTP scripting page.
You can only use cURL to transfer files via FTP. If you're trying to upload a video to a web server using their web interface or an API or similiar than cURL is not your tool.

How to properly format body for post request?

I'm using a firefox pluing called restclient to simulate a post request. It doesnt' seem to be picking up any post data, but not sure if I'm formatting it properly.
using header: Content-Type: application/json
and body: {"id":1234}
but not go, it's not picking up the id parameter in my php, is there some special formatting I need to set?
okay, got it working, here is what is needed
two content types:
Content-Type: application/json
Content-Type: application/x-www-form-urlencoded
and then set your params like so in body:
param1=value1&param2=value2
Thanks for the help everyone.
PHP will not parse a JSON body automatically into the $_POST superglobal. That only happens with application/x-www-form-urlencoded and multipart/form-data POST bodies. That said, you can parse the body yourself — you can access the raw POST body via the php://input pseudo-stream.

Categories