setRequestHeader not working in enyo.xhr.request - enyo

I am working on enyo.xhr. To create a request, i am using enyo.xhr.request with parameters having url and type of method. But i am facing problem while setting the requestHeader to some range of bytes.
It is showing an error having "xhr object is no longer usable".
I have checked that it is possible with XmlHttpRequest() using setRequestHeader() with parameter as Range and passing the respective value. But how could we set the Request header using enyo.xhr.request().

xhr for Post request:
var xhr = enyo.xhr.request({url:url,method:'POST',
headers:{"content-type":"application/x-www-form-urlencoded"},
body: reqBody ,sync:false});
where:
URL is some URL,
reqBody is baseString,
Can include as many headers you want?
Has this answered your question?

Related

Uri.https on Flutter is limiting the length of my url

I'm trying to make a get request to Firebase. In my url, I have to send the auth token which is very long (more than 900 characters). I create the url this way:
var url =
Uri.https('firebaseio.com', '/mydb.json?auth=$authToken&orderBy="userId"&equalTo="$userId');
But the url is not complete when I print it (the last characters are always lacking) and hence the request does not work. Anyone knows a solution for that?
Your URL isn't actually being cut. The print function can have a limit on its line length when being using in Flutter. Look elsewhere for your issue.
It likely has something to do with your misuse of quotes within your string. It's not normal to have quotes in your query parameters that are opened but not closed.
You can also improve this code by using the optional third queryParameters parameter of the Uri.https constructor to handle your query parameters:
var url = Uri.https(
'firebaseio.com',
'/mydb.json',
{
'auth': authToken,
'orderBy': '"userId"',
'equalTo': '"$userId"',
},
);

Set Request Header keyword in Robot Framework doesn't set header as expected

I am setting custom header for POST method using HttpLibrary.HTTP keyword Set Request Header
But when I run the test case, in wireshark I don't see POST method going with the header value I set.
Also library doesn't compute Content-Length.
As per the code header is set in kwargs[] parameter, but the content in the parameter is not sent while doing Http POST.
kwargs = {}
if 'Content-Type' in self._request_headers:
kwargs['content_type'] = self._request_headers['Content-Type']
self._response = self.app.post(url, self._request_body or {}, self._request_headers, **kwargs
post is done to the requestted url but header is not set as expected
I ran into this same problem, and I found that I was using the combination of 'Create New HTTP Context' and 'GET' wrong. It turns out you should only give the part of the url that hasn't already been specified in the 'Create New HTTP Context' keyword
Incorrect:
Create New HTTP Context | mywebsite.com
Set Request Header | key | value
Get http://mywebsite.com/specific/uri
Correct:
Create New HTTP Context | mywebsite.com
Set Request Header | key | value
Get /specific/uri

HTTP request parameters are not available by request.getAttribute()

I am sending an url parameter to servlet using the following jQuery piece:
$.getJSON("http://localhost:8080/JsoupPrj/JasonGen?url=" + url, function(data) {
$("#content").html(data);
});
On the server side, the servlet gets the parameter, for that I coded as below:
String url = (String) request.getAttribute("url");
But it is not working, can you tell me where I am doing wrong? I believe I am not passing the parameter properly to the servlet. The servlet triggers each time through the JavaScript, but it is not seeing the parameters passed from the browser.
Here,
String url = (String) request.getAttribute("url");
you're trying to get a request parameter as a request attribute instead of as a request parameter. This will obviously not do what you want.
You need to get a request parameter as a request parameter, not as a request attribute.
String url = request.getParameter("url");
Unrelated to the concrete problem: you don't seem to be URL-encoding the parameter at all before sending. This will possibly cause other problems, unrelated to this one, when the url contains special characters. Look at the JS encodeURIComponent() function, or the data argument of the $.getJSON() function. See for more hints also How to use Servlets and Ajax?

How do we pass parameters when doing HTTP Post?

I am working on an app where we have to pass specific web api parameters to a web app using HTTP POST.
eg:
apimethod name
parameter1 value
parameter2 value
So do I use a string or URLEncodedPostData to send that data?
It would be good if u help me with a code eg.
I am using something like this but it doesnt post the data to the server.
Though the response code is ok/200 and I also get get a parsed html response when i read the httpresponse input stream. But the code doesnt post anything. So unable to get the expected response.
_postData.append("method", "session.getToken");
_postData.append( "developerKey", "value");
_postData.append( "clientID", "value");
_httpConnection = (HttpConnection) Connector.open(URL, Connector.READ_WRITE);
String encodedData = _postData.toString();
_httpConnection.setRequestMethod(HttpConnection.POST);
_httpConnection.setRequestProperty("User-Agent", "BlackBerry/3.2.1");
_httpConnection.setRequestProperty("Content-Language", "en-US");
_httpConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
_httpConnection.setRequestProperty("Content-Length",(new Integer(encodedData.length())).toString());
os = _httpConnection.openOutputStream();
os.write(requeststring.getBytes());`
The code you posted above looks correct - although you'll want to do a few more things (maybe you did this already but didn't include it in your code):
Close the outputstream once you've written all the bytes to it
Call getResponseCode() on the connection so that it actually sends the request
POSTed parameters are usually sent in the response BODY, which means URL-encoding them is inappropriate. Quote from the HTTP/1.1 protocol:
Note: The "multipart/form-data" type has been specifically defined
for carrying form data suitable for processing via the POST
request method, as described in RFC 1867 [15].
The post method allows you to use pretty arbitrary message bodies — so it is whatever format the server wants.

How to perform an HTTP POST request in ASP?

How would I go about creating a HTTP request with POST data in classic asp (not .net) ?
You can try something like this:
Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
ServerXmlHttp.open "POST", "http://www.example.com/page.asp"
ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ServerXmlHttp.setRequestHeader "Content-Length", Len(PostData)
ServerXmlHttp.send PostData
If ServerXmlHttp.status = 200 Then
TextResponse = ServerXmlHttp.responseText
XMLResponse = ServerXmlHttp.responseXML
StreamResponse = ServerXmlHttp.responseStream
Else
' Handle missing response or other errors here
End If
Set ServerXmlHttp = Nothing
where PostData is the data you want to post (eg name-value pairs, XML document or whatever).
You'll need to set the correct version of MSXML2.ServerXMLHTTP to match what you have installed.
The open method takes five arguments, of which only the first two are required:
ServerXmlHttp.open Method, URL, Async, User, Password
Method: "GET" or "POST"
URL: the URL you want to post to
Async: the default is False (the call doesn't return immediately) - set to True for an asynchronous call
User: the user name required for authentication
Password: the password required for authentication
When the call returns, the status property holds the HTTP status. A value of 200 means OK - 404 means not found, 500 means server error etc. (See http://en.wikipedia.org/wiki/List_of_HTTP_status_codes for other values.)
You can get the response as text (responseText property), XML (responseXML property) or a stream (responseStream property).
You must use one of the existing xmlhttp server objects directly or you could use a library which makes life a bit easier by abstracting the low level stuff away.
Check ajaxed implementation of fetching an URL
Disadvantage: You need to configure the library in order to make it work. Not sure if this is necessary for your project.

Resources