Posting Format

109 views
Skip to first unread message

Antony Lawlor

unread,
Apr 3, 2014, 5:23:30 AM4/3/14
to guz...@googlegroups.com
Hi guy's, I have been stuck on this problem for a few days now. Here is what the code looks like,

$httpClient->post('/car/about/submit/'.$linkUID.'&'.$thestr)->send();

My first question is, can I post like this? and is there any way I can get the raw post info i.e. headers raw string etc that guzzle is actually posting? I just want to see what it looks like before I jump to any conclusion of what it might be that is causing the problem. I am pretty sure that i have my $thestr (which is my post data) formatted right, but going through the code and trying to parse it out is time consuming.

I did get this message when i put the above piece of code in a try catch.

 Client error response [status code] 400 [reason phrase] Bad Request [url]

After reading on w3c about 400 it would suggest that the url that I have put together is wrong and the server cannot handle it, i really need a way to dump exactly what guzzle is posting so i can compair it to what the server is expecting.

W3C about 400 status:

10.4.1 400 Bad Request

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

The url that I have put together contains about 70 different pieces of post data, so it's hard to go through it, I have dumped the $thestr and went through it, from what I can see it is formatted correctly but its so big, that i could be wrong, and guzzle could be changing something when it is posting it. This is why i need to try and dump the raw guzzle post.

Any help is much appreciated,
Thanks,


- Anton.
 

Michael Dowling

unread,
Apr 3, 2014, 12:12:10 PM4/3/14
to guz...@googlegroups.com
The request you are sending is a POST request, but it isn't sending anything in the body. You're sending stuff in the query string.

Here are the Guzzle 4 POST docs: http://docs.guzzlephp.org/en/latest/quickstart.html#post-requests

In guzzle 3, there's no way to see the post data being sent over the wire without using a tcpdump. In Guzzle 4, you can just use the history subscriber: http://docs.guzzlephp.org/en/latest/testing.html#history-subscriber

-Michael

Antony Lawlor

unread,
Apr 4, 2014, 5:16:29 AM4/4/14
to guz...@googlegroups.com
Thanks for the reply Michael, I had a problem where I had to post 2 of the same pieces of data for example fname=true&fname=false don't ask me why the website expects that because I am still trying to figure that out my self lol. This brings me on the my next point, this is how I originally had the post working,

$httpClient->post('/car-insurance/aboutthepolicy/submit/'', array(), $theAry)->send();

But because i had this double data problem i couldnt have 2 indexes in the array with the same key name, fname.

so this is whey i wanted to use a string, that way I dont have the problem with array, so do you reacon that this,

$httpClient->post('/car/about/submit/'.$linkUID.'&'.$thestr)->send();

should look like this

$httpClient->post('/car/about/submit/', $linkUID.'&'.$thestr)->send(); ? so it was just the comma separating the '/car/about/submit/' from the $linkUID.'&'.$thestr that I was missing? the comma separate that post and tells the function, ok every thing after this comma is the body, post it. So really I haven't been posting any thing lol?


Thanks for all you're help I am still learning and really appreciate it.

- Anton.

Antony Lawlor

unread,
Apr 4, 2014, 3:00:56 PM4/4/14
to guz...@googlegroups.com
Ok so after reading through the documents more, I feel the code I now have is right, what do you think?

$httpClient->post('https://www.thewebsite.com/car/about/submit/', ['body' => $topost]);

The $topost variable contains a long string of data to be posted.

Does that seem ok? and I would be right in saying that if I am still getting errors it is due to me posting something wrong in the $topost variable.

Dowling, Michael

unread,
Apr 4, 2014, 3:03:33 PM4/4/14
to guz...@googlegroups.com
That looks right now. What errors are you getting?

--Michael

Antony Lawlor

unread,
Apr 6, 2014, 8:39:03 AM4/6/14
to guz...@googlegroups.com
I found out the reason I was getting an error was because I was posting some wrong data, I am just post my array as per the documentation thanks for you're help.

- Anton

Reply all
Reply to author
Forward
0 new messages