Re: Issues with sending JSON payload via POST request

"alfinhaji ." <[email protected]> Fri, 23 Sep 2016 11:54:16 -0400
Newsgroups gmane.comp.java.grinder.user
Message-ID <CACqy2Tp4qFhTQ-ysOYsQDP-qt9E43xKMSrmXdgM=hEHnozUTOA@mail.gmail.com>
--===============8895910780854022329==
Content-Type: multipart/alternative; boundary=001a1144263665b7f9053d2ecab2

--001a1144263665b7f9053d2ecab2
Content-Type: text/plain; charset=UTF-8

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

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

<div dir=3D"ltr">What I generally do in these cases is configure a proxy in=
 the grinder properties and have my request go through Fiddler to capture t=
he request.=C2=A0 If inspecting the headers and body in fiddler does not ex=
pose the issue with the request, I then compare it to a successful use case=
, such as running it through another utility/tool/browser whatever, =C2=A0w=
here I get a successful request through, again proxy through Fiddler, and c=
ompare 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:[email protected]" target=3D"_blank">cola.vn@gma=
il.com</a>&gt;</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">Greetings!<div><br></div><div><p style=3D"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;seg=
oe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:14px;margin-top:0px=
">The requirement is to make a POST request to a particular URL with a give=
n 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-bottom:16px;colo=
r:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui=
&quot;,roboto,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quo=
t;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:14px">This is =
my code:</p><div><br></div><div><pre style=3D"font-family:consolas,&quot;li=
beration mono&quot;,menlo,courier,monospace;font-size:11.9px;margin-top:0px=
;margin-bottom:16px;font-stretch:normal;line-height:1.45;word-wrap:normal;p=
adding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3=
px;color:rgb(51,51,51)"><code style=3D"font-family:consolas,&quot;liberatio=
n mono&quot;,menlo,courier,monospace;font-size:11.9px;padding:0px;margin:0p=
x;background-image:initial;background-position:initial;background-repeat:in=
itial;background-color:transparent;border-radius:3px;word-break:normal;bord=
er:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal=
">request1 =3D HTTPRequest()
control =3D HTTPPluginControl.<wbr>getConnectionDefaults()
httpUtilities =3D HTTPPluginControl.<wbr>getHTTPUtilities()
control.setProxyServer(&quot;<a href=3D"http://proxy.example.com" target=3D=
"_blank">proxy.<wbr>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.<wbr>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.<wbr>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>------------------------------<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></div>

--001a1144263665b7f9053d2ecab2--


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

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

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

--===============8895910780854022329==--