HTTP post request rejected
Hi guys,
I'm looking to mimic this Post request URL where I'm sending a token :.png)
So I created the below code but I'm getting "HTTP/1.1 405 Method Not Allowed" error
s Url="myurl/confirmed?id="_token
Set Httprequest1=##class(%Net.HttpRequest).%New()
Set Httprequest1.SSLConfiguration="LS2"
Set Httprequest1.Server="myserver.com"
Set Httprequest1.Timeout=30
Set Httprequest1.Https=1
Set Httprequest1.Port=7711
set Httprequest1.ContentType="application/json"
Do Httprequest1.SetHeader("Accept","application/json")
Do Httprequest1.SetHeader("Accept-Language","en_US")
//D Httprequest1.EntityBody.Write(token)
Set tSc=Httprequest1.Post(Url)
Set StateLine=Httprequest1.HttpResponse.StatusLine
S ^Out2($zdt($h),1)=tSc_"|"_StateLine
So what am I doing wrong ?
Thanks
Comments
The error "HTTP/1.1 405 Method Not Allowed" occurs when the HTTP method used in the request is not supported by the server for the specified URL. Servers typically allow specific methods (GET, POST, PUT, DELETE, etc.) for different HTTP endpoints.
For your code, here are potential issues and solutions:
URL Mapping Issue: If the server is configured to accept only certain HTTP methods for this endpoint (e.g.,
GET), trying to send aPOSTrequest will result in the "Method Not Allowed" error. You need to verify the endpoint's supported HTTP methods. If the endpoint requiresPOSTbut your URLMap configuration is set only toGET, then you must add thePOSTmethod to the allowed methods list in the URLMap configuration [1].Correct Method Implementation: Ensure that the endpoint is properly implemented to handle all necessary HTTP methods (
GET,POST, etc.). When implementing REST APIs, different HTTP verbs should typically map to the appropriate operations without duplicating insert/delete actions inside the URL. For CRUD operations, it is better to keep the same URL and differentiate actions with HTTP methods. For example:- POST for creating a resource
- DELETE for deleting a resource You may need to modify the server configuration or code accordingly [1].
Content Type Header: Ensure the
ContentTypeheader matches what the server expects. You setapplication/jsonin your code, but if the server expectsapplication/x-www-form-urlencodedfor the POST body, you will need to modify this. Also, confirm whether the token is being passed in the correct format and location (e.g., as a query parameter, JSON payload, etc.) that matches the endpoint specifications [1].
Refer to suggestions for RESTful implementation and troubleshooting configurations in your application [1].
Sources:
Are you sure that the tool (browser? does not look like Postman) you use in the first picture is using a POST andf not a GET method?
The "405 Method Not Allowed" error means that POST (as used in your code) is not allowed.