java - HttpUrlConnection headers response code is 403 -


the response http code of given snippet @ end of post 403. 403 means forbidded. accessing , posting through google chrome postman app. unable resolve problem in case. have tried many other solutions like:

httpurlconnection.setrequestproperty("authorization","basic "+header);

httpurlconnection.setrequestproperty("apikey","abcd1234");

  httpurlconnection httpurlconnection = (httpurlconnection) (new url ("http:abc.com")).openconnection();             httpurlconnection.setdooutput(true);             httpurlconnection.setrequestmethod("post");             httpurlconnection.setrequestproperty("authorization",header);           //  header = "apikey:abcd1234" ;             httpurlconnection.setrequestproperty("content-type","application/json"); 

basic authentication data needs baase64 encoded,

string encoded = base64.encode(username+":"+password); connection.setrequestproperty("authorization", "basic "+encoded); 

Comments