function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hithesh SaicharanHithesh Saicharan 

Simple Rest service always giving Bad Message 400

I am planning to implement connected API for my application. So as a start I just wrote simple httpPost method and checked whether I can able to hit through post man.
and here is my simple code
@RestResource(urlMapping='/PostToChatter')
global class GetChatter{
    @HTTPPost
    global static void createChatterRecords(){
       
          System.debug('Success >>>');
          RestResponse response = RestContext.response;
          response.addHeader('Content-Type', 'application/json');
          response.responseBody = Blob.valueOf('{ "Excuted succesfully" : "EXECUTED" }');
          response.statusCode = 201;
    }
}

Inorder to hit this method I created connected app and after giving client id, client secret, user name , password i got access_token as below
User-added image
00D2v000001e2OE!ARsAQHzfP_5D0wui2bSyRFg_M8slkwU3pK2t7cB99lqrMNDB8es1aDluf46dL.RpLKQQxPJrM1fwQyyfhG0NmfEeegB4h.b2

and here is my instance URL
 
https://hitheshm-dev-ed.lightning.force.com/services/apexrest/PostToChatter

and even I tried with 
https://hitheshm-dev-ed.my.salesforce.com/services/apexrest/PostToChatter

User-added imagebut I am always getting
 
<h1>Bad Message 400</h1>
<pre>reason: No Host</pre>

For Headers I tried with Authorization = Bearer <access_token> or Authorization = OAuth <access_token>
and noting is working. I am not doing any fancy coding here. Not sure why its not working.
PS: Since this is my dev org I am sharing my access token. Later I will change the token once it got worked.
Best Answer chosen by Hithesh Saicharan
Hithesh SaicharanHithesh Saicharan
Issue is with my Postman. Now its looking good after re installing post man

All Answers

Hithesh SaicharanHithesh Saicharan
Issue is with my Postman. Now its looking good after re installing post man
This was selected as the best answer
AnudeepAnudeep (Salesforce Developers) 
I recommend trying this with the command line window

See example here

Let me know if it helps
SwethaSwetha (Salesforce Developers) 
HI Hithesh,
I tried this at my end and could successfully get an expected response

User-added image
In case you are using an older version of the postman, it does not permit/fetch to use the access token in your post-call.

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you