http-request

How to make http put request with zip file in nodejs

大城市里の小女人 提交于 2019-12-07 15:29:07
问题 I want to make a http PUT request with zip file in binary to a web api and get response with http status code. How to read the file and PUT it with binary ? Thank you for your help!! 回答1: You can start with this: var http = require('http'); var fs = require('fs'); var req = http.request({ hostname : HOSTNAME, port : PORT, path : UPLOAD_PATH, method : 'PUT', }); fs.createReadStream('somefile.zip').pipe(req); You may need to perform some other actions, like proper error handling, setting

404 Not Found when try getting OAuth2 access token in spring application

為{幸葍}努か 提交于 2019-12-07 03:13:21
I am trying to make a web application that we can get an access token in 'password' grant type by just call some http basic request For example When I call http://localhost:8080/demo4ssh-security-oauth2/oauth/token?client_id=mobile_1&client_secret=secret_1&grant_type=password&username=zhangsan&password=123456 I can get the following token {"access_token":"4219a91f-45d5-4a07-9e8e-3acbadd0c23e","token_type":"bearer","refresh_token":"d41df9fd-3d36-4a20-b0b7-1a1883c7439d","expires_in":43199,"scope":"read write trust"} However my token site always return 404. I try to do some searches on web but

Using Python-Requests Library to Post a Text File

走远了吗. 提交于 2019-12-06 13:35:19
Hi I'm having trouble posting a text file using the Python Requests Library ( http://docs.python-requests.org/en/latest/index.html ), can you let me know what I'm doing wrong? I tried searching for related questions and found this Send file using POST from a Python script but it doesn't answer my question. Here's my code: import codecs import requests # Create a text file savedTextFile = codecs.open('mytextfile.txt', 'w', 'UTF-8') # Add some text to it savedTextFile.write("line one text for example\n and line two text for example") # Post the file THIS IS WHERE I GET REALLY TRIPPED UP

Nativescript - How to POST Image with http.request

心不动则不痛 提交于 2019-12-06 06:53:17
Help, I need call the http.request for send Image captured in camera api in my NativeScript App. I capture the photo in camera api for nativescript and need send to api in upload process. Follow the code about this process: var frameModule = require("ui/frame"); var viewModule = require("ui/core/view"); var Observable = require("data/observable").Observable; var config = require("../../shared/config"); var cameraModule = require("camera"); var imageModule = require("ui/image"); var http = require("http"); exports.loaded = function(args) { var page = args.object; viewModel = new Observable({

How to determine Content Type of a HTTP Servlet Request?

混江龙づ霸主 提交于 2019-12-06 06:08:21
How can I get the content type from the HttpServletRequest without reading the request body? When I use the following, I get null : request.getContentType() When I try to read the JSON data that comes in the request body using the following: StringBuilder jsonsb = new StringBuilder(); BufferedReader jsonbr = request.getReader(); The request.getReader() throws Caused by: java.lang.NullPointerException: null at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:106) I even tried using the following and was able to get the content type but, still getting the same NullPointerException

How to make http put request with zip file in nodejs

佐手、 提交于 2019-12-06 02:51:33
I want to make a http PUT request with zip file in binary to a web api and get response with http status code. How to read the file and PUT it with binary ? Thank you for your help!! You can start with this: var http = require('http'); var fs = require('fs'); var req = http.request({ hostname : HOSTNAME, port : PORT, path : UPLOAD_PATH, method : 'PUT', }); fs.createReadStream('somefile.zip').pipe(req); You may need to perform some other actions, like proper error handling, setting Content-Type headers, etc. Using request-promise (based on bluebird) const fs = require('fs'); const request =

Accessing the raw http request in MVC4

蓝咒 提交于 2019-12-06 00:12:55
There are a lot of questions about accessing the HttpRequest on stackoverflow already, but I have not been able to find one that I can use yet. If somebody could point me to an answer I would be grateful. My problem is that I want to modify an existing application in the simplest way possible in order to add in full request logging. I'm aware there this can be done with Http modules and IIS logging or using Log4net etc etc. But I don't want to use any of these techniques because the application is unpredictable so I need a solution that does not require any configuration changes at all. I have

Adding missing request parameter before persistance in Sails.JS

空扰寡人 提交于 2019-12-05 22:54:31
Is it possible to "insert" a missing parameter (in case it was not sent), in order to persist them all via req.params.all() ? Currently trying to do so, gets me a no method 'setParameter' error. It's not possible to add anything into the result of req.params.all() in Sails without implementing custom middleware, since it's parsed at request time and provided to route handlers before any user-level code runs. However, if what you're looking for is default parameter options, in Sails v0.10.x you can use the req.options hash for this. If you wanted to set a default limit for a blueprint "find",

Tornado - What is the difference between RequestHandler's get_argument(), get_query_argument() and get_body_argument()?

别来无恙 提交于 2019-12-05 04:18:03
When to use RequestHandler.get_argument() , RequestHandler.get_query_argument() and RequestHandler.get_body_argument() ? What is the use-case for each of them? Also what does the request.body and request.argument do in these cases? Which are to be used in which scenarios? And, is there a request.query or something similar too? Most HTTP requests store extra parameters (say, form values) in one of two places: the URL (in the form of a ?foo=bar&spam=eggs query string ), or in the request body (when using a POST request and either the application/x-www-form-urlencoded or multipart/form-data mime

Python Requests Module & JSON Responses

≡放荡痞女 提交于 2019-12-05 01:02:17
问题 I am using the awesome Requests module to test an API I've created for one of our internal projects. I believe I have discovered what is either a flaw in the Requests module itself, or a flaw in my usage of it. Because our data is not super sensitive, our API uses simple, basic HTTP authentication to control acces. When I make requests of the API URL, using JSON as the data format and either urllib2 with HTTPBasicAuthHandler or PHP and cURL, I get my data back as a properly formatted JSON