Quantcast

Issues with sending JSON payload via POST request

classic Classic list List threaded Threaded
6 messages Options
Izy
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Issues with sending JSON payload via POST request

Izy
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with sending JSON payload via POST request

alfinhaji
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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use



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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use
Izy
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with sending JSON payload via POST request

Izy

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 ." <[hidden email]> 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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use



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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use


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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with sending JSON payload via POST request

Marc Holden
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 <[hidden email]> 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 ." <[hidden email]> 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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use



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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use

------------------------------------------------------------------------------
_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use

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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use
Izy
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with sending JSON payload via POST request

Izy
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 <[hidden email]> 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 <[hidden email]> 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 ." <[hidden email]> 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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use



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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use

------------------------------------------------------------------------------
_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use

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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use




--
Regards
Rohit Nambiar
+91 9008475760

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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issues with sending JSON payload via POST request

Tom Vitez

Hi Izy,

 

Definitely sounds like an AUTH issue. Have you included the following JVM argument in your grinder.properties?

grinder.jvm.arguments = -Dhttps.protocols=TLSv1

 

If it doesn’t help/resolve your problem, I would follow Alfin’s advise and run on a local machine where you could run a success & failure scenario through a proxy like Fiddler.

 

BR,

 

Tom

 

From: Rohit Nambiar [mailto:[hidden email]]
Sent: Tuesday, September 27, 2016 2:00 AM
To: grinder-use <[hidden email]>
Subject: Re: [Grinder-use] Issues with sending JSON payload via POST request

 

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 <[hidden email]> 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 <[hidden email]> 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 ." <[hidden email]> 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 <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use

 


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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use

------------------------------------------------------------------------------
_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use


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

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use



 

--

Regards

Rohit Nambiar

+91 9008475760


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use
Loading...