Question
· 18 hr ago

HTTP post request rejected

Hi guys,

I'm looking to mimic this Post request URL where I'm sending a token :

So I created the below code but I'm getting "HTTP/1.1 405 Method Not Allowed" error 

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
^Out2($zdt($h),1)=tSc_"|"_StateLine

So what am I doing wrong ?

Thanks

Product version: IRIS 2024.3
Discussion (3)3
Log in or sign up to continue

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:

  1. URL Mapping Issue: If the server is configured to accept only certain HTTP methods for this endpoint (e.g., GET), trying to send a POST request will result in the "Method Not Allowed" error. You need to verify the endpoint's supported HTTP methods. If the endpoint requires POST but your URLMap configuration is set only to GET, then you must add the POST method to the allowed methods list in the URLMap configuration [1].

  2. 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].
  3. Content Type Header: Ensure the ContentType header matches what the server expects. You set application/json in your code, but if the server expects application/x-www-form-urlencoded for 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: