Re: Issues with sending JSON payload via POST request
Rohit Nambiar <[email protected]> Tue, 27 Sep 2016 11:29:37 +0530
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <CAHvE9BK6Eq02LGHf=d2tgBzS7aYWnhaaJrPW=+cAW9cUxzhvWw@mail.gmail.com> |
--===============5896350123917457709== Content-Type: multipart/alternative; boundary=001a1145a8542708c4053d76f349 --001a1145a8542708c4053d76f349 Content-Type: text/plain; charset=UTF-8 So what I've realized is that it's not even the JSON data. When I modify the JSON data, it doesn't make a difference, I still get a 403. I have a strong suspicion that the issue is with Grinder accessing the port 6443. The system on which Grinder is running is able to access it because a curl from that system with the payload and url, etc. works. But nGrinder is unable to. The proxy itself is not allowing the request from nGrinder. Is there some rule that Grinder can only access certain ports? And that I need to enable the use of a port that doesn't fall in that list? On Fri, Sep 23, 2016 at 11:13 PM, Marc Holden <[email protected]> wrote: > If you are getting a 403 - Forbidden, do you need to log into the app with > credentials the are authorized to hit that URL? Are any headers missing? > Do you need to make a GET request before you can post to that endpoint (the > GET may force the setting of headers the application is looking for)? > > A 403 seems to indicate a problem with endpoint and not the payload or is > a 403 expected for invalid JSON? Do you have access to application logs > which may indicate why the message is being rejected. > > This sounds like a header issue to me... > > > > > > > On Fri, Sep 23, 2016 at 1:02 PM Rohit Nambiar <[email protected]> wrote: > >> 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 >>> >>> ------------------------------------------------------------ >> ------------------ >> _______________________________________________ >> 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 > > -- Regards Rohit Nambiar +91 9008475760 --001a1145a8542708c4053d76f349 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">So what I've realized is that it's not even the JS= ON data. When I modify the JSON data, it doesn't make a difference, I s= till get a 403. I have a strong suspicion that the issue is with Grinder ac= cessing the port 6443. The system on which Grinder is running is able to ac= cess it because a curl from that system with the payload and url, etc. work= s. But nGrinder is unable to. The proxy itself is not allowing the request = from nGrinder. Is there some rule that Grinder can only access certain port= s? And that I need to enable the use of a port that doesn't fall in tha= t list?</div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On F= ri, Sep 23, 2016 at 11:13 PM, Marc Holden <span dir=3D"ltr"><<a href=3D"= mailto:[email protected]" target=3D"_blank">[email protected]</a>>= </span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .= 8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">If you ar= e getting a 403 - Forbidden, do you need to log into the app with credentia= ls the are authorized to hit that URL?=C2=A0 Are any headers missing?=C2=A0= Do you need to make a GET request before you can post to that endpoint (th= e GET may force the setting of headers the application is looking for)?=C2= =A0<div><br><div>A 403 seems to indicate a problem with endpoint and not th= e payload or is a 403 expected for invalid JSON? Do you have access to appl= ication logs which may indicate why the message is being rejected.</div><di= v><br></div><div>This sounds like a header issue to me...</div><div><div cl= ass=3D"h5"><div><br></div><div><br><div><br></div><div><br><div><br></div><= div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Fri, Sep 23, 2016 at= 1:02 PM Rohit Nambiar <<a href=3D"mailto:[email protected]" target=3D"_= blank">[email protected]</a>> wrote:<br></div><blockquote class=3D"gmail= _quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:= 1ex"><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]" = target=3D"_blank">[email protected]</a>> wrote:<br type=3D"attribution= "><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:= 1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">What I generally do in th= ese cases is configure a proxy in the grinder properties and have my reques= t go through Fiddler to capture the request.=C2=A0 If inspecting the header= s and body in fiddler does not expose the issue with the request, I then co= mpare it to a successful use case, such as running it through another utili= ty/tool/browser whatever, =C2=A0where I get a successful request through, a= gain proxy through Fiddler, and compare my two requests (pass-case and fail= -case) using a diff utility, such as WinMerge.=C2=A0 I generally always can= find what is missing, either in my headers or body.=C2=A0</div><div class= =3D"gmail_extra"><br><div class=3D"gmail_quote">On Fri, Sep 23, 2016 at 11:= 40 AM, Rohit Nambiar <span dir=3D"ltr"><<a href=3D"mailto:cola.vn@gmail.= com" target=3D"_blank">[email protected]</a>></span> wrote:<br><blockquo= te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so= lid;padding-left:1ex"><div dir=3D"ltr">Greetings!<div><br></div><div><p sty= le=3D"margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blin= kmacsystemfont,"segoe ui",roboto,helvetica,arial,sans-serif,"= ;apple color emoji","segoe ui emoji","segoe ui symbol&q= uot;;font-size:14px;margin-top:0px">The requirement is to make a POST reque= st 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"marg= in-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system= ,blinkmacsystemfont,"segoe ui",roboto,helvetica,arial,sans-serif,= "apple color emoji","segoe ui emoji","segoe ui sym= bol";font-size:14px">This is my code:</p><div><br></div><div><pre styl= e=3D"font-family:consolas,"liberation mono",menlo,courier,monospa= ce;font-size:11.9px;margin-top:0px;margin-bottom:16px;font-stretch:normal;l= ine-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-colo= r:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)"><code style=3D"fo= nt-family:consolas,"liberation mono",menlo,courier,monospace;font= -size:11.9px;padding:0px;margin:0px;background-image:initial;background-pos= ition:initial;background-repeat:initial;background-color:transparent;border= -radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;li= ne-height:inherit;word-wrap:normal">request1 =3D HTTPRequest() control =3D HTTPPluginControl.<wbr>getConnectionDefaults() httpUtilities =3D HTTPPluginControl.<wbr>getHTTPUtilities() 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.<wbr>something.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.<wbr>com: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]" 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></div> ------------------------------<wbr>------------------------------<wbr>-----= -------------<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> </blockquote></div></div></div></div></div></div></div></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><br><br clear=3D"all"><div><br></div>-- <br><div cla= ss=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr">= Regards<div>Rohit Nambiar</div><div>+91 9008475760</div></div></div> </div> --001a1145a8542708c4053d76f349-- --===============5896350123917457709== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ --===============5896350123917457709== 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 --===============5896350123917457709==--