java - 405 - method not allowed calling web service from struts -


I have a data access object that calls the web service. In my browser, I can hit the web service using a URL and it is successful.

  http: // mycompany: 9080 / reporting manager / service / repManHealth / importHistoryTrafficLightStatus.json   

 Enter the image details here

But when trying to execute the code, in my data access object, I get a 405 error saying method Not allowed.

  string request request = "http: // mycompany: 9080 / reporting manager / service / repManHealth / importHistoryTrafficLightStatus.json"; Url url = new url (request urai); HttpURL connection httpCon = (HttpURLConnection) url.openConnection (); HttpCon.setDoOutput (true); HttpCon.setRequestMethod ("GET"); HttpCon.setRequestProperty ("Accept", "App / JS"); OutputStream Water Out = New OutputStream Water (httpCon.getOutputStream ()); Int ResponseCode = httpCon.getResponseCode (); String response message = httpCon.getResponseMessage (); BufferedRadder RD = New buffed reader (new inputtreamreader (httpCon.getInputStream ())); Stringbuffer sb = new stringbuffer (); String line = null; While ((line = rd.readline ()) = null) {sb.append (line); } Rd.close (); String jsonResponse = sb.toString (); Out.close (); HttpCon.disconnect ();   

Can anyone help me who might be wrong here?

Also, is there a better way to execute the web service for an external application and read the response using struts? Or do people think that this method is right?

Thanks

Get the method you are using, try the following code

  string url = String.Format ("http://somedomain.com/samplerequest?greeting={0}", absolute); Web Client Service Request = New Webclient (); ServiceRequest.Headers [HttpRequestHeader.ContentType] = "App / Jason"; String response = serviceRequest.DownloadString (new URI (url));    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -