Re: Issues with sending JSON payload via POST request
Rohit Nambiar <[email protected]> Fri, 23 Sep 2016 22:28:53 +0530
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <CAHvE9BJsEAXV8HtJWAmUCrYia_AUmryOYV75TSCvS6UAzLZdpA@mail.gmail.com> |
--===============2821035165066248365== Content-Type: multipart/alternative; boundary=001a113ed28a806818053d2fb184 --001a113ed28a806818053d2fb184 Content-Type: text/plain; charset=UTF-8 Hello Alfin, Thanks for the speedy response. However, in my situation, grinder is running on a remote machine I have only terminal access to. Hence, running fiddler or the likes on my machine gives me only the response and not the request. I had run fiddler on a DHC call I made from my machine. On analyzing the request sent, everything seemed to be the same as my grinder request. Im not able to single out on where the problem is, but I suspect it's with the way the JSON data is being passed to the uri. Anyone else in a similar position? Regards Izy On Sep 23, 2016 9:28 PM, "alfinhaji ." <[email protected]> wrote: > What I generally do in these cases is configure a proxy in the grinder > properties and have my request go through Fiddler to capture the request. > If inspecting the headers and body in fiddler does not expose the issue > with the request, I then compare it to a successful use case, such as > running it through another utility/tool/browser whatever, where I get a > successful request through, again proxy through Fiddler, and compare my two > requests (pass-case and fail-case) using a diff utility, such as WinMerge. > I generally always can find what is missing, either in my headers or body. > > On Fri, Sep 23, 2016 at 11:40 AM, Rohit Nambiar <[email protected]> wrote: > >> Greetings! >> >> The requirement is to make a POST request to a particular URL with a >> given JSON payload. The URL will only respond if the payload is correct and >> the request is via POST. >> >> This is my code: >> >> request1 = HTTPRequest() >> control = HTTPPluginControl.getConnectionDefaults() >> httpUtilities = HTTPPluginControl.getHTTPUtilities() >> control.setProxyServer("proxy.example.com", 1234) >> >> payload = JSONObject({ >> "uaaURL": "https://com-example.something.com", >> "sampleID": "admin", >> "sampleSecret": "password", >> "sampleID2": "example-sample-el", >> "sampleSecret2": "ssenjsoemal/+11=", >> "username": "test", >> "someAttributes": { >> "Groups": [ >> "example_com-abc" >> ], >> "attribute": [ >> "value1" >> ] >> } >> }) >> payload = str(payload) >> >> url = "https://example-something.com:6443/getvalues" >> headers = [ >> NVPair('Content-Type', 'application/json'), >> NVPair('Charset', 'UTF-8'),] >> >> class TestRunner: >> def __call__(self): >> result = request1.POST(url, payload, headers) >> print payload, headers >> >> The issue with this is that my POST request gives me a 403 forbidden. >> But, when I send the same request using DHC, it gives me a 200 OK. So I'm >> sure the payload is correct. The proxy also I've tested in another script >> and works fine. >> >> I'm not able to understand why this is happening and I've been sitting on >> this for a long time! Any ideas? Thanks in advance! :D >> >> >> Regards >> Izy >> >> ------------------------------------------------------------ >> ------------------ >> >> _______________________________________________ >> grinder-use mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/grinder-use >> >> > > ------------------------------------------------------------ > ------------------ > > _______________________________________________ > grinder-use mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/grinder-use > > --001a113ed28a806818053d2fb184 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p dir=3D"ltr">Hello Alfin, </p> <p dir=3D"ltr">Thanks for the speedy response. However, in my situation, gr= inder is running on a remote machine I have only terminal access to. Hence,= running fiddler or the likes on my machine gives me only the response and = not the request. I had run fiddler on a DHC call I made from my machine. On= analyzing the request sent, everything seemed to be the same as my grinder= request. Im not able to single out on where the problem is, but I suspect = it's with the way the JSON data is being passed to the uri. Anyone else= in a similar position? </p> <p dir=3D"ltr">Regards<br> Izy</p> <div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Sep 23, 2016 9= :28 PM, "alfinhaji ." <<a href=3D"mailto:[email protected]">= [email protected]</a>> wrote:<br type=3D"attribution"><blockquote clas= s=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad= ding-left:1ex"><div dir=3D"ltr">What I generally do in these cases is confi= gure a proxy in the grinder properties and have my request go through Fiddl= er to capture the request.=C2=A0 If inspecting the headers and body in fidd= ler does not expose the issue with the request, I then compare it to a succ= essful use case, such as running it through another utility/tool/browser wh= atever, =C2=A0where I get a successful request through, again proxy through= Fiddler, and compare my two requests (pass-case and fail-case) using a dif= f utility, such as WinMerge.=C2=A0 I generally always can find what is miss= ing, either in my headers or body.=C2=A0</div><div class=3D"gmail_extra"><b= r><div class=3D"gmail_quote">On Fri, Sep 23, 2016 at 11:40 AM, Rohit Nambia= r <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=3D"_bla= nk">[email protected]</a>></span> wrote:<br><blockquote class=3D"gmail_q= uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e= x"><div dir=3D"ltr">Greetings!<div><br></div><div><p style=3D"margin-bottom= :16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quo= t;segoe ui",roboto,helvetica,arial,sans-serif,"apple color emoji&= quot;,"segoe ui emoji","segoe ui symbol";font-size:14px= ;margin-top:0px">The requirement is to make a POST request to a particular = URL with a given JSON payload. The URL will only respond if the payload is = correct and the request is via POST.</p><p style=3D"margin-top:0px;margin-b= ottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont= ,"segoe ui",roboto,helvetica,arial,sans-serif,"apple color e= moji","segoe ui emoji","segoe ui symbol";font-size= :14px">This is my code:</p><div><br></div><div><pre style=3D"font-family:co= nsolas,"liberation mono",menlo,courier,monospace;font-size:11.9px= ;margin-top:0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;wor= d-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);= border-radius:3px;color:rgb(51,51,51)"><code style=3D"font-family:consolas,= "liberation mono",menlo,courier,monospace;font-size:11.9px;paddin= g:0px;margin:0px;background-image:initial;background-position:initial;backg= round-repeat:initial;background-color:transparent;border-radius:3px;word-br= eak:normal;border:0px;display:inline;overflow:visible;line-height:inherit;w= ord-wrap:normal">request1 =3D HTTPRequest() control =3D HTTPPluginControl.getConnectio<wbr>nDefaults() httpUtilities =3D HTTPPluginControl.getHTTPUtili<wbr>ties() control.setProxyServer("<a href=3D"http://proxy.example.com" target=3D= "_blank">proxy.<wbr>example.com</a>", 1234) payload =3D JSONObject({ "uaaURL": "<a href=3D"https://com-example.something.com" t= arget=3D"_blank">https://com-example.something<wbr>.com</a>", "sampleID": "admin", "sampleSecret": "password", "sampleID2": "example-sample-el", "sampleSecret2": "ssenjsoemal/+11=3D", "username": "test", "someAttributes": { "Groups": [ "example_com-abc" ], "attribute": [ "value1" ] } }) payload =3D str(payload) url =3D "<a href=3D"https://example-something.com:6443/getvalues" targ= et=3D"_blank">https://example-something.com<wbr>:6443/getvalues</a>" headers =3D [ NVPair('Content-Type', 'application/json'), NVPair('Charset', 'UTF-8'),] class TestRunner: def __call__(self): result =3D request1.POST(url, payload, headers) print payload, headers</code></pre><div><p style=3D"margin-top:0px;= margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsy= stemfont,"segoe ui",roboto,helvetica,arial,sans-serif,"apple= color emoji","segoe ui emoji","segoe ui symbol";f= ont-size:14px">The issue with this is that my POST request gives me a 403 f= orbidden. But, when I send the same request using DHC, it gives me a 200 OK= . So I'm sure the payload is correct. The proxy also I've tested in= another script and works fine.</p><p style=3D"margin-top:0px;color:rgb(51,= 51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",ro= boto,helvetica,arial,sans-serif,"apple color emoji","segoe u= i emoji","segoe ui symbol";font-size:14px;margin-bottom:0px"= >I'm not able to understand why this is happening and I've been sit= ting on this for a long time! Any ideas? Thanks in advance! :D</p><p style= =3D"margin-top:0px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsy= stemfont,"segoe ui",roboto,helvetica,arial,sans-serif,"apple= color emoji","segoe ui emoji","segoe ui symbol";f= ont-size:14px;margin-bottom:0px"><br></p></div><div><div>Regards</div><div>= Izy</div></div> </div></div></div> <br>------------------------------<wbr>------------------------------<wbr>-= -----------------<br> <br>______________________________<wbr>_________________<br> grinder-use mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">grin= [email protected]<wbr>net</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/grinder-use" rel=3D= "noreferrer" target=3D"_blank">https://lists.sourceforge.net/<wbr>lists/lis= tinfo/grinder-use</a><br> <br></blockquote></div><br></div> <br>------------------------------<wbr>------------------------------<wbr>-= -----------------<br> <br>______________________________<wbr>_________________<br> grinder-use mailing list<br> <a href=3D"mailto:[email protected]">[email protected]= ceforge.<wbr>net</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/grinder-use" rel=3D= "noreferrer" target=3D"_blank">https://lists.sourceforge.net/<wbr>lists/lis= tinfo/grinder-use</a><br> <br></blockquote></div></div> --001a113ed28a806818053d2fb184-- --===============2821035165066248365== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ --===============2821035165066248365== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ grinder-use mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/grinder-use --===============2821035165066248365==--