POST request through microgateway.
I tried to call my API (POST) through microgateway and got "ErrorMessage=Request is empty or null" error. I think something wrong with my request. I do it using "Fiddler".
Header:
User-Agent: Fiddler
Authorization: Bearer ...
Content-Type: application/json
Host: ....
Content-Length: ...
Body:
{
"Value1":"val1",
"Value2":"val2".
"Value3":"val3"
}
What's wrong with my request? Please note that "GET" works fine.
Can you get more debug info? Pls see http://docs.apigee.com/microgateway/content/edge-microgateway-operations on how to run in debug mode.
Thank you for your answer ... I checked it more detailed using VS Debug.
POST http://my-host:8000/service/addr
Authorization: Bearer ...
Content-Type: application/json
User-Agent: Fiddler
Host: ...
Content-Length: ....
Body:
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3"
}
I received the request on the API side but arg (body) is null.
HttpActionContext.ActionArguments - key is correct, value is null.
"ErrorMessage=Request is empty or null" is my API error message.
I think "Content-Type: application/json" is the reason of the issue.
Please note that sometimes the request finishes successfully.
Thank you for your answer ... I checked it more detailed using VS Debug.
POST http://my-host:8000/service/addr
Authorization: Bearer ...
Content-Type: application/json
User-Agent: Fiddler
Host: ...
Content-Length: ....
Body:
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3"
}
I received the request on the API side but arg (body) is null.
HttpActionContext.ActionArguments - key is correct, value is null.
"ErrorMessage=Request is empty or null" is my API error message.
I think "Content-Type: application/json" is the reason of the issue.
Please note that sometimes the request finishes successfully.
What is the response if you send that request to your API directly?
HttpResponseMessage: HttpStatusCode.Created, int?
I received the request on the API side but arg (body) is null.
HttpActionContext.ActionArguments - key is correct, value is null.
"ErrorMessage=Request is empty or null" is my API error message.
Does anyone have any ideas?
Hmm Is your target application something I can hit? If you are not comfortable putting that publicly then you can send me an email pjhaATapigeeDOTcom. @shawn feldman Can you help dig more pls?
I'm afraid that I can't share my source code ... I think my comment contains enough information...
I don't know what should I check because I can call my API and can debug it. I can see request but argument is empty. (Please note that sometimes argument is not empty but request (body, header, url) is the same)
default.yaml===============
agent: min_uptime: 5000 spin_sleep_time: 1000 max_times: 300 port: 9000
edge_config: bootstrap: 'https://edgemicroservices-us-east-1.apigee.net/edgemicro/bootstrap/organization/createapi/environment/test' jwt_public_key: 'https://createapi-test.apigee.net/edgemicro-auth/publicKey'
edgemicro: home: ../gateway port: 8000 max_connections: -1 max_connections_hard: -1
logging: level: info dir: /var/tmp stats_log_interval: 60
plugins: dir: ../plugins sequence: - analytics
headers: x-forwarded-for: true x-forwarded-host: true x-request-id: true x-response-time: true via: true oauth: allowNoAuthorization: true allowInvalidAuthorization: true
So ... I found the reason of my trouble but can't find out.
My previous post was a little bit different than real.
I can see arg if I call
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3"
}
and null for
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3",
"MyObject":{"Id":111}
}
Type of Id is "int?". Type of MyObject is "public class".
But ... I can see arg if body:
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3",
"MyObject":{}
}
Just to make sure if have it correct you are sending
POST http://myapi/.
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3",
"MyObject":{"Id":111}
}
and receive a response of request body empty or null?
Just to make sure if have it correct you are sending
POST http://myapi/.
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3",
"MyObject":{"Id":111}
}
and receive a response of request body empty or null?
I receive (API side) null request body (API method arg).
POST: http://localhost:8000/. (I use micro gateway)
HEADER:
Connection: keep-alive
Authorization: Bearer .....
Content-Type: application/json
Content-Length: ...
Host: localhost:8000
BODY:
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3",
"MyObject":{"Id":111}
}
If i send
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3",
"MyObject":{}
} body, I receive correct request body (API arg)
i'm going to test this on my side, one other question, what is the correct request body? are expecting the gateway just not to error out?
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3",
"MyObject":{"Id":111}
} - I receive NULL (I don't receive the body on API side but controller method is called.)
{
"Value1": "val1",
"Value2": "val2",
"Value3": "val3",
"MyObject":{}
} - I receive it on the API side (MyClass.Value1 ="val1", MyClass.Value2 ="val2", MyClass.Value3 ="val3", MyObject = MySubObj object) as required.
public class MyClass
{
public string Value1 { get; set; }
public string Value2 { get; set; }
public string Value3 { get; set; }
public MySubObj MyObject { get; set; }
}
public class MySubObj
{
public int? Id { get; set; }
public string StoreId { get; set; }
}
Please note that sometimes (1 of ~20) I receive correct data.
i'll be taking a look at this in my environment, i'll let you know on monday where i get
@TestAppUser what does the raw traffic look like between the microgateway and your api? can you place fiddler in between the two and let me know what the request/reply between microgateway and your api is? my email is sfeldman@apigee.com if you want to contact me directly
just want to verify that there is nothing in C#/.NET deserialization that is creating issues, testing the same api on my side looks ok, but i am using nodejs
what plugins are you running besides analytics? wondering if a plugin is modifying the request, therefore the content length is not correct for the .NET deserializer.
I added additional properties to my configuration:
<Property name="allow.POST.without.content.length">false</Property>
<Property name="request.retain.headers">User-Agent,Content-Length</Property>
<Property name="compression.algorithm">none</Property>
default.yaml
---------------------------------------------
agent:
min_uptime: 5000
spin_sleep_time: 1000
max_times: 300
port: 9000
edge_config: bootstrap: https://apigee.net/edgemicro/bootstrap/organization/org/environment/env. jwt_public_key: http://apigee.net/edgemicro/publicKey.
edgemicro:
home: ../gateway
port: 8000
max_connections: -1
max_connections_hard: -1
logging:
level: info
dir: /var/tmp
stats_log_interval: 60
plugins:
dir: ../plugins
sequence:
- analytics
headers:
x-forwarded-for: true
x-forwarded-host: true
x-request-id: true
x-response-time: true
via: true
oauth:
allowNoAuthorization: true
allowInvalidAuthorization: true
---------------------------------------------------
Regarding content length. My body is a little bit different but It doesn't depend on properties name and content.
I found that I received Header with Transfer-Encoding: chunked but I sent Content-Lenght: ... If I send Content-Lenght:187 (according body) I receive correct body, If I send Content-Lenght:188 (according body) I receive null. But doc ... and I set "allow.POST.without.content.length - false"
Maybe it depends on size of body.
Please note that sometimes request finished successfully (the first request more often than next).
Original request after gateway:
=================================
POST http://localhost:8888/rfps HTTP/1.1
connection: keep-alive
authorization: Bearer ...........
content-type: application/json
user-agent: Fiddler
x-request-id: MTQ1NTA4OTY3NzM1OQ.2
x-forwarded-for: ::1
x-forwarded-host: localhost:8000
via: 1.1 localhost
Host: localhost:8888
Transfer-Encoding: chunked
bc
{"Number": "RFPNumber",
"Trade": "AUTO DOOR",
"Description": "Test",
"ProviderId": 2000000109,
"ProposalNotificationEmail": "PrpEmail@ee.by",
"ProviderEmail": "223ProEmail@ee.by"}
0
=================================
The first request finished successfully (I received correct arg). The next one I received null.
Also:
Sometimes the following error happens:
Error: read ECONNRESET at exports._errnoException (util.js:870:11) at TCP.onread (net.js:544:26) installed plugin from D:\APIgee\apigee-edge-micro-1.1.1\plugins\analytics MTQ1NTAyNDUxMjI2MA edge micro listening on port 8000 events.js:141 throw er; // Unhandled 'error' event ^
So ...
If I set accumulate-request plugin the request finished successfully
plugins: dir: ../plugins sequence: - analytics - accumulate-request
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |