Https post request in android App - https

How to show progress in percentage on uploading data by using https multipart entity?
i am posting data using -
HttpResponse httpResponse = httpClient.execute(httpPost,httpContext);

Related

How to send request data in post request using zuul filter

I am new to Zuul and I want to redirect to external url using zuul pre filter in spring boot application. I want to send request data to call external url (post method api in python).
When i try to send request data using below code, when i hit the url from postman,i get 405 The method is not allowed for the requested URL.
my code:
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
InputStream in = request.getInputStream();
String body = StreamUtils.copyToString(in, Charset.forName("UTF-8"));
ctx.set(body);
when i hit the url like http://localhost:8080/customers/ passing request body in postman,it should redirect to external url (api method) by sending post data but i am getting getting 405 The method is not allowed for the requested URL.
Could any one please help me in solving this issue? I want to send request data in zuul and call external api. Thank you

How does postman app set request body for a GET request

When I was trying in browser to send a GET request with data from bootstrap datatable ajax to a C# MVC controller method, not all the data that was send was mapped to the model object. Some properties in the model object still remained with null/default value.
I verified the property names and no issues in that. But when I did the same thing in postman app the data was successfully bound to the model object.
Two things that I noted in the postman app is that:
The request data is not send in the query string parameter rather in
the request body with still the method type as GET (I don't know
how that is possible), but in browser as usual the data was URL
encoded and was sent as query string parameter.
In post man app the request headers also contains "Content-Type"
header with "application/json" as value.
So I also tried with "Content-Type" header with "application/json" but still no use the data was not bound.
Finally I chose the common way, I just set the "Content-Type" header with "application/json", stringified the data with JSON.stringify and I set the type as "POST" and it successfully got mapped.
What I got struggling is, how does the postman app alone can send a GET request like that with data in the request body.
If anyone has idea about this please tell me that would help me to have an idea about the HTTP requests.
1.) PostMan - GET Request Format
2.) PostMan - Get Request Network Data
3.) PostMan - Get Request Network Data - Raw Format
4.) Backend - Contoller Received Data
1.) Browser - GET Request Format
2.) Browser - Query String Parameters
3.) Backend - Contoller Received Data

django-wkhtmltopdf with AJAX requests will get 403 Forbidden

Description
I want to generate a PDF file from Django view, so I'm using django-wkhtmltopdf app, the app is working but my template (that is used in the view) has many AJAX requests using jQuery. Views that requested by AJAX requests are protected by csrf token.
Issue
All AJAX requests are getting 403 Forbidden response because of CSRF verification failed.
Trial
I tried django-cors-headers and still getting the same responses.

Ionicview and ionic serve CORS

My ionic app is connecting to asp.net web api on azure. The API already allow all origin to access and the API_KEY header. However I am still getting Message
"The origin 'http://localhost:8100' is not allowed." on both Ionic serve and ionic view
Code in ionic app
var headers = new Headers();
headers.append('API_KEY', 'X-some-key');
headers.delete("Origin");
let options = new RequestOptions({ headers: headers});
return this.http.get(url, options);
request and response header when using ionic serve
Found the answer from here : CORS enabled but response for preflight has invalid HTTP status code 404 when POSTing JSON
The problem is backend doesn't have OPTIONS handler, added OPTIONS handler in web.config works.

Unable to add custom header to response

I am unable to add a custom header to a response that is returned from render():
response = render(request, 'my_template.html', {'ctx1': 1, 'ctx2': 2})
response['My-Custom-Header'] = 'abc12345'
return response
This is a response to an Ajax request initiated using jQuery's $.get(). On Chrome, the response has the template rendered properly, but it does not have the custom header. If I print the response object before returning, I see that it has my custom header.
I thought the issue was because of this answer, so I added Django middleware to add a header to all responses:
class CustomHeaderMiddleware():
def process_response(self, request, response):
response['Access-Control-Expose-Headers'] = 'My-Custom-Header'
return response
All my responses now have header Access-Control-Expose-Headers: My-Custom-Header, but I still see this issue.
My request is local; I'm using the Django development web server.
If I send a non-Ajax GET request, whatever custom header I add in Django is visible in the response on Chrome. So this issue seems to be limited to Ajax requests.
I am using Django 1.11.4 and Python2.
[edit]
If I capture the response in WireShark, I see that it does not have My-Custom-Header. Furthermore, if I add a custom header to the response dictionary in the above middleware, the header shows up in Wireshark and is visible in Chrome. So this seems to be a Django issue with responses to Ajax requests.
This issue is unrelated to Ajax. I was calling my view using this template tag. The custom response headers are lost because of line 32 in that code.

Resources