Search code examples
djangorestdjango-rest-frameworkwso2

send POST request in wso2 api manager 4.1.0


I want to send a POST request with a body in WSO2. actually, I have a Django rest framework with some APIs and want to send requests in WSO2 API manager. it's all OK for GET, DELETE but when I want to POST some request I'll receive a bad request from Django server.
Django server is running on http://localhost:8000/user-api/users/
in wso2 api publisher api's URL is : http://localhost:8243/users/1.0.0
endpoint in wso2 is : http://localhost:8000/user-api/users/

the below picture is what I receive when I send GET request:
response on GET request

I send POST request with this json as body:
post request's json
and here is what I receive when I send POST request:
servers response on POST request

Everything is ok when I check the server's URL in my browser.

UPDATE:
when I use my Django server as a gateway for WSO2 everything is OK but when I use default WSO2-Gateway everything goes wrong.


Solution

  • I'm not clear about what this question is really asking. But I feel this is generally asking how to debug this situation. I apologize if I got that wrong.

    To start debugging a problem with a WSO2 server in the mix there are some common things to think about:

    1. If this is a local or development region can I use http, instead of https, so that I can view things as plain text during debugging activities.

    2. For the Enterprise Integrator products there is a test feature for back end endpoints in the admin Console. This can often be helpful to ensure communication can happen. It's like a simple ping.

    3. Check inside the trace.log to see if there is anything helpful for you.

    4. For APIM use the Test a REST API feature to try out the backend to see if that works before coming in the front door of the server.

    5. For WSO2 products if reviewing logs aren't giving enough information then you can use the Wirelogs to enable you to view every piece of information that goes in and out of the WSO2 server. These are formatted roughly like Wireshark logs but the output is inside of the wso2carbon.log file. The key here is getting used to the >> and << to determine if the log entry is going out of or into the WSO2 server.

    6. If you still can't find the issue then you might need to go down to reviewing the data as it goes across the wire. This is a bit complex at first but you'll quickly get the hang of it. (Hint: This is extremely helpful for trouble shooting JMS communication.)

    On linux you can use tcpdump to write data to file and then open it with Wireshark. Windows has a similar system.

    For tcpdump you need to use the interface name. It's often like eth0. You can find t using ifconfig. It's the value: before the flags.

    Example tcpdump capture:

    tcpdump -s 0 -I {interfacename} -W 30 -C 50 -w wsoei-01-07192022.pcap -Z root
    tcpdump -s 0 -i ens192 -W 30 -C 50 -w wsoei-01-07192022.pcap -Z root
    

    Once you have the pcap file captured you then use Wireshark to open it. And there you have it you can see everything that went across the wire. Once you have that you can start to see at what point things are breaking down.

    Conclusion

    If you zoom in close enough with your research you will eventually find where the breakdown is.