Submit a "pure" HTTP request from HTML page - html

I need to send the following HTTP request to my REST server from an HTML page to retrieve another page. How to do that using javascript or forms or links or whatever ?
Note that the HTTP request body must contain plain text with no key/value pairs as a form usually does.
PUT /somerequest HTTP/1.1
Host: www.myhost.com
Accept: text/html,application/xhtml+xml
Payload of the request to be read by the server script.
The script will return a HTML content to my browser.
Thanks !

You could use jQuery?
http://api.jquery.com/jQuery.ajax/
I'm sure you will find what you want there.
And if you don't look at a lower layer: XMLHttpRequest
http://www.w3.org/TR/XMLHttpRequest/

Related

How to see final html when http requesting

I call a http request to get the html of a url. The same also happens, for example, when doing "view source" in Firefox. As you know, the html is different than the final html of the site as it is seen in the browser itself.
Is there a way to call the http request of a url and "do something" so I will have the final "version" of the html including everything that is there when the site ends to load?
The Firefox was an example, I meant calling a http request with a http client, using Java for example. I call a http request to get the html but the html is the "before" state.
Thanks

How set HTTP *Request* header programmatically (e.g. by <a> -tag, <link> -tag, or by JavaScript)?

This question is about HTTP Request headers -- not HTTP Response headers.
Is there any way to programmatically make User Agents add or change any HTTP Request Header e.g. by means of HTML, JavaScript, for links or resources from a web page. There exists some HTTP Request Headers that one would think should be able to be controlled programmatically, for example max-stale.
(One could for example imagine that some optional attribute for HTML-elements <a>, <link>, <img> <script> etc, could exist that would cause the User Agent to add/change a HTTP request header in its request to the server, but I have not found such an attribute. Similarly, one could think that there should exist some mechanism to control HTTP Request Headers when AJAX is used.)
Turning around the question ...: Why does the HTTP Request Header max-stale exist at all if it cannot be controlled?
Thanks!
The XMLHTTPResponse setRequestHeader() method can be used to set HTTP request headers for an AJAX request. Various JavaScript libraries expose this function in different ways. For example, with jQuery.ajax() you would set the headers property of the settings parameter.
There are some ways in which you can affect request headers in html, e.g. via a form's enctype attribute. I do not believe there is any way to actually specify the actual header values in html.
For Ajax you can specify request headers, though the browser will block certain headers from being set, I doubt max-stale is one of them.
Also not only browsers make http request, there are a whole host of applications that do and any of them could easily set the max-stale header if they wanted.

Restfullyii prepending <link> tag to the json response

Hi I'm new to restfulyii
I'm having a problem with the json response a tag is being prepended
Refer to the code below
(just assume that there are '<>' for the link tag)
<link rel="stylesheet" type="text/css" href="/assets/e5ba1689/srbac.css" />{"success":true,"message":"Record(s) Found","data":{"totalCount":1,"share":[{"id":"0","elementid":"1","type":"video","suid":"1","duid":"5","permissions":"superuser"}]}}
this coming from api/ under GET method and same with other rest verbs
I can't parse my JSON data because of the prepended line.
Please help..
reference:
localhost/api/ - method: GET/POST/PUT/DELETE
Everything is working fine with restful yii except that json response format...
Thanks in advance!
Ohmel Paguirigan
The problem seams to be that YII is not recognizing that your request is an actual Ajax request.
Search in srbac/components/Helper.php for:
if (!Yii::app()->request->isAjaxRequest){
Yii::app()->clientScript->registerCssFile($cssFile);
}
You will notice that SRBAC is checking if your request is an actual Ajax request.
Yoshi on the Yii Forms says that:
yii checks if there is a X-Requested-With HTTP header set (which
should result in an $_SERVER['HTTP_X_REQUESTED_WITH'] server variable)
and whether it contains the string 'XMLHttpRequest'. But this is a
custom header set by most javascript libraries (and so does jQuery).
There are e.g. some proxies which drop these custom headers (mainly
for security reasons) and therefore your application can't recognize
whether it's an ajax request or not. It's not 100% reliable.
Therefore, you must make sure that your javascript library is injecting this Header.
To do this in Javascript, in your app.run
add the following:
$http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
Then, all of y our http requests in angular will send the header yii needs to discern that an AjaxRequest is being sent!
Hope this helps!

how to set the authorization in html email

I am sending an html email which refers to some images on amazon s3. The images need an authorization in http header. Specifically they need this:
curl -H 'Authorization: '
How can I provide that empty space authorization the the html email?
You cannot.
HTML provides no means to specify custom HTTP headers for requests.
If you were using a browser, you could use JavaScript with XMLHttpRequest to make the request and then convert the response into a data: URI and use that as the src of the image. HTML formatted email has no such option though.

How to get result back from CGI(C) to the same HTML page?

Can I display the result which is processed in the CGI(using C) on the same html page, from where the CGI is invoked?
Regards,
MalarN
No, HTTP does not work that way.
You would have to make a asyncronious request (using JavaScript, this is commonly known as AJAX) instead.
In a nutshell, you can spawn a background HTTP request to your CGI process, instead of posting the browser to it in the main HTTP request.
See this: http://en.wikipedia.org/wiki/XMLHttpRequest