httpresponse

Android: Http response cookie store

橙三吉。 提交于 2019-12-08 07:44:17
问题 I cant find any resource to understand how cookies are set by the Http response in Android. I am hitting a URL and reading the response like so: HttpGet httpGet = new HttpGet(url); HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); String entityStr = EntityUtils.toString(entity); } I am told that Http response will set a cookie that

JSON response is returning as text

◇◆丶佛笑我妖孽 提交于 2019-12-08 05:57:13
问题 I have composed JSON response as below in my java servlet, where JObject is the JSON object created response.setContentType("application/json; charset=UTF-8"); PrintWriter printout = response.getWriter(); printout.print(JObject); printout.flush(); But it got received as text/plain in the receiving side [Server: Apache-Coyote/1.1, ETag: W/"XXXXXXXXXX", Last-Modified: Tue, 04 Jun 2013 10:42:31 GMT, Content-Type: text/plain, Content-Length: 2573, Date: Tue, 04 Jun 2013 10:44:01 GMT] How to get

get a “raw” request\response from MITM Proxy

徘徊边缘 提交于 2019-12-07 18:08:46
问题 i', scripting mitm proxy (http://mitmproxy.org/index.html) to write HTTP and HTTPS request and responses to a file according to their IP (each client can then access it's own requests\responses) for unit tests for mobile. As far as i can see for now i can't just use str(Flow.request) or repr(Flow.request) to get a "raw" print of the response\request like i get in fiddler, i need to reconstruct it from the internal data of the Request and Response objects. anyone knows of a better way ? i'm

Creating http response as a return value for mockito

梦想与她 提交于 2019-12-07 17:30:33
I am new to Mockito testing and am testing a GET request. I have mocked the call but now I need to return HttpResponse<Cars[]> because these values are later used in for loop. How can I create a dummy HttpResponse where the body contains the array of Car objects. The method where Get request is used in class CarProvider is: public HttpResponse<Cars[]> getCars(String carId, String carname) { return Unirest.get(endpointUrl) .header("Accept", MediaType.APPLICATION_JSON) .queryString("carId",cardId) .queryString("carname",carname) .asObject(Cars[].class); } This is used in another class CarsUsers

When using an API route, return Http Response 401 instead of redirect to login page when not authorised

怎甘沉沦 提交于 2019-12-07 16:00:21
问题 I'm building an ASP.NET Core 2.0 website using MVC and WebAPI to provide access to a series of microservices. Where a WebAPI controller requires a user to be authenticated and authorised (using the Authorize attribute), any unauthorised or not-logged in user gets the response back as the entire HTML for the MVC login page. When unauthorised users access the API, I would like to return the HTTP status code 401 and its associated error message in the response, instead of an entire HTML page. I

How can I pass a moderately large volume of data to my Web API app?

无人久伴 提交于 2019-12-07 15:00:20
问题 I've got this code in a Web API Controller: [Route("{unit}/{begindate}/{enddate}")] [HttpPost] public void Post(string unit, string begindate, string enddate, [FromBody] string stringifiedjsondata) { List<ProduceUsageSPResults> _produceUsageList = JsonConvert.DeserializeObject<List<ProduceUsageSPResults>>(stringifiedjsondata); string _unit = unit; string _begindate = String.Format("{0}01", HyphenizeYYYYMM(begindate)); string _enddate = GetEndOfMonthFor(enddate); string appDataFolder =

with servicestack how can i prevent cookies being added to the response?

余生长醉 提交于 2019-12-07 13:46:50
问题 I can remove the cookies after the fact, with this: public override void Configure(Funq.Container container) { ResponseFilters.Add((req, res, dto) => { ((HttpListenerResponse)res.OriginalResponse).Headers.Remove("Set-Cookie"); }); } I have also considered overriding the SetCookie method of HttpResponse to just ditch the cookies, but I am not sure how to override that behaviour in servicestack. Question: How can I ensure no cookies are added to my responses in the first place? This seems more

Which file types can be viewed in browser (inline, without a plugin)

一笑奈何 提交于 2019-12-07 13:40:30
问题 I just want to know which file types (like .png, .pdf, .txt) can be viewed in browser (like Chrome, Firefox). Because sometimes when i click on file link, instead of displaying in browser it download automatically. Why this happens ? Below is my code. Any help will be appreciated. <script> function openPDF(url){ var w=window.open(url, '_blank'); w.focus(); } </script> <a href="burger1.jpg" target='_blank'>link</a> <div onclick="openPDF('1.pdf');">PDF 1</div> 回答1: In normal cases, following

Returning binary data with django HttpResponse

南楼画角 提交于 2019-12-07 12:43:38
问题 I'm trying to get Django's HttpResponse to return binary data without much success. I've been trying different methods for a while now, but without success. Encoding the string to ASCII works as long as the binary data values aren't outside the ASCII char scope, which is smaller than 0-255. The same happened when encoding with latin-1. Creating byte string works nicely, but seems to fail if certain values are included, for example, if I have the following bytes included in the data: "\xf6\x52

HTTP reponse for error in REST call for Mojolicious

人盡茶涼 提交于 2019-12-07 12:21:01
问题 The mojolicious application that I use is JSON based, that is the interaction between the client and the server is more of an exchange of JSON structured data. I am trying to implement a standard way of handling errors with proper HTTP response code when an error occurs during one of the REST calls. What is the best way of implementing such a standard and where do I do it? I see a couple of ways of doing it Create a class and list all the error response and its associated content, a call