Issues with sending JSON payload via POST request
Rohit Nambiar <[email protected]> Fri, 23 Sep 2016 21:10:28 +0530
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <CAHvE9BJdvC5So=JP=yZ_0qOuS=k83ZWt68GQ_FDvbu+7+n21uQ@mail.gmail.com> |
--===============5819516759720217831==
Content-Type: multipart/alternative; boundary=001a113ed28a03d58e053d2e99dd
--001a113ed28a03d58e053d2e99dd
Content-Type: text/plain; charset=UTF-8
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
--001a113ed28a03d58e053d2e99dd
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Greetings!<div><br></div><div><p style=3D"box-sizing:borde=
r-box;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"box-=
sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);fon=
t-family:-apple-system,blinkmacsystemfont,"segoe ui",roboto,helve=
tica,arial,sans-serif,"apple color emoji","segoe ui emoji&qu=
ot;,"segoe ui symbol";font-size:14px">This is my code:</p><div><b=
r></div><div><pre style=3D"box-sizing:border-box;font-family:consolas,"=
;liberation mono",menlo,courier,monospace;font-size:11.9px;margin-top:=
0px;margin-bottom:16px;font-stretch:normal;line-height:1.45;word-wrap:norma=
l;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radiu=
s:3px;color:rgb(51,51,51)"><code style=3D"box-sizing:border-box;font-family=
:consolas,"liberation mono",menlo,courier,monospace;font-size:11.=
9px;padding:0px;margin:0px;background-image:initial;background-position:ini=
tial;background-size:initial;background-repeat:initial;background-origin:in=
itial;background-clip:initial;background-color:transparent;border-radius:3p=
x;word-break:normal;border:0px;display:inline;overflow:visible;line-height:=
inherit;word-wrap:normal">request1 =3D HTTPRequest()
control =3D HTTPPluginControl.getConnectionDefaults()
httpUtilities =3D HTTPPluginControl.getHTTPUtilities()
control.setProxyServer("<a href=3D"http://proxy.example.com">proxy.exa=
mple.com</a>", 1234)
payload =3D JSONObject({
"uaaURL": "<a href=3D"https://com-example.something.com">h=
ttps://com-example.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">http=
s://example-something.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"box-sizing:bord=
er-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-a=
pple-system,blinkmacsystemfont,"segoe ui",roboto,helvetica,arial,=
sans-serif,"apple color emoji","segoe ui emoji","s=
egoe ui symbol";font-size:14px">The issue with this is that my POST re=
quest 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 a=
lso I've tested in another script and works fine.</p><p style=3D"box-si=
zing:border-box;margin-top:0px;color:rgb(51,51,51);font-family:-apple-syste=
m,blinkmacsystemfont,"segoe ui",roboto,helvetica,arial,sans-serif=
,"apple color emoji","segoe ui emoji","segoe ui sy=
mbol";font-size:14px;margin-bottom:0px">I'm not able to understand=
why this is happening and I've been sitting on this for a long time! A=
ny ideas? Thanks in advance! :D</p><p style=3D"box-sizing:border-box;margin=
-top:0px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&=
quot;segoe ui",roboto,helvetica,arial,sans-serif,"apple color emo=
ji","segoe ui emoji","segoe ui symbol";font-size:1=
4px;margin-bottom:0px"><br></p></div><div class=3D"gmail_signature"><div>Re=
gards</div><div>Izy</div></div>
</div></div></div>
--001a113ed28a03d58e053d2e99dd--
--===============5819516759720217831==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
--===============5819516759720217831==
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
--===============5819516759720217831==--