Re: Issues with sending JSON payload via POST request

Marc Holden <[email protected]> Fri, 23 Sep 2016 17:43:41 +0000
Newsgroups gmane.comp.java.grinder.user
Message-ID <CADV_OVVL_j_V3wnkBcw7QP5WNdj2LRnkGg=TZL92mch3o_15Vg@mail.gmail.com>
--===============8777336215686709062==
Content-Type: multipart/alternative; boundary=94eb2c0b228053a749053d305230

--94eb2c0b228053a749053d305230
Content-Type: text/plain; charset=UTF-8

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
>

--94eb2c0b228053a749053d305230
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">If you are getting a 403 - Forbidden, do you need to log i=
nto the app with credentials 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 (the GET may force the setting of headers the applic=
ation is looking for)?=C2=A0<div><br><div>A 403 seems to indicate a problem=
 with endpoint and not the payload or is a 403 expected for invalid JSON? D=
o you have access to application logs which may indicate why the message is=
 being rejected.</div><div><br></div><div>This sounds like a header issue t=
o me...</div><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 &lt;<a href=3D"mailto:[email protected]" target=3D=
"_blank">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t: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&#39;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, &quot;alfinhaji .&quot; &lt;<a href=3D"mailto:[email protected]" =
target=3D"_blank">[email protected]</a>&gt; 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">&lt;<a href=3D"mailto:cola.vn@gmail.=
com" target=3D"_blank">[email protected]</a>&gt;</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,&quot;segoe ui&quot;,roboto,helvetica,arial,sans-serif,&quot=
;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;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,&quot;segoe ui&quot;,roboto,helvetica,arial,sans-serif,=
&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui sym=
bol&quot;;font-size:14px">This is my code:</p><div><br></div><div><pre styl=
e=3D"font-family:consolas,&quot;liberation mono&quot;,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,&quot;liberation mono&quot;,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.getConnectionDefaults()
httpUtilities =3D HTTPPluginControl.getHTTPUtilities()
control.setProxyServer(&quot;<a href=3D"http://proxy.example.com" target=3D=
"_blank">proxy.example.com</a>&quot;, 1234)

payload =3D JSONObject({
  &quot;uaaURL&quot;: &quot;<a href=3D"https://com-example.something.com" t=
arget=3D"_blank">https://com-example.something.com</a>&quot;,
  &quot;sampleID&quot;: &quot;admin&quot;,
  &quot;sampleSecret&quot;: &quot;password&quot;,
  &quot;sampleID2&quot;: &quot;example-sample-el&quot;,
  &quot;sampleSecret2&quot;: &quot;ssenjsoemal/+11=3D&quot;,
  &quot;username&quot;: &quot;test&quot;,
  &quot;someAttributes&quot;: {
    &quot;Groups&quot;: [
      &quot;example_com-abc&quot;
    ],
    &quot;attribute&quot;: [
      &quot;value1&quot;
    ]
  }
})
payload =3D str(payload)

url =3D &quot;<a href=3D"https://example-something.com:6443/getvalues" targ=
et=3D"_blank">https://example-something.com:6443/getvalues</a>&quot;
headers =3D [
    NVPair(&#39;Content-Type&#39;, &#39;application/json&#39;),
    NVPair(&#39;Charset&#39;, &#39;UTF-8&#39;),]

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,&quot;segoe ui&quot;,roboto,helvetica,arial,sans-serif,&quot;apple=
 color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;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&#39;m sure the payload is correct. The proxy also I&#39;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,&quot;segoe ui&quot;,ro=
boto,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe u=
i emoji&quot;,&quot;segoe ui symbol&quot;;font-size:14px;margin-bottom:0px"=
>I&#39;m not able to understand why this is happening and I&#39;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,&quot;segoe ui&quot;,roboto,helvetica,arial,sans-serif,&quot;apple=
 color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;f=
ont-size:14px;margin-bottom:0px"><br></p></div><div><div>Regards</div><div>=
Izy</div></div>
</div></div></div>
<br>-----------------------------------------------------------------------=
-------<br>
<br>_______________________________________________<br>
grinder-use mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">grin=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/grinder-use" rel=3D=
"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo=
/grinder-use</a><br>
<br></blockquote></div><br></div>
<br>-----------------------------------------------------------------------=
-------<br>
<br>_______________________________________________<br>
grinder-use mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">grin=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/grinder-use" rel=3D=
"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo=
/grinder-use</a><br>
<br></blockquote></div></div>
---------------------------------------------------------------------------=
---<br>
_______________________________________________<br>
grinder-use mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">grin=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/grinder-use" rel=3D=
"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo=
/grinder-use</a><br>
</blockquote></div></div></div></div></div></div>

--94eb2c0b228053a749053d305230--


--===============8777336215686709062==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------

--===============8777336215686709062==
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

--===============8777336215686709062==--