-4
POST /1.1/statuses/update.json?include_entities=true HTTP/1.1
Accept: */*
Connection: close
User-Agent: OAuth gem v0.4.4
Content-Type: application/x-www-form-urlencoded
Content-Length: 76
Host: api.twitter.com

status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21

How to do an http request, I'm a newbie in Javascript and i need to post a tweet with the api (and i need to implement the sign in button) but I don't understand how to implement this http request.

Thanks in advance

Oraekia
  • 1,167
  • 2
  • 7
  • 14

3 Answers3

1

You can use jquery plugin to do this so easy:

$.post("/1.1/statuses/update.json",
{
    include_entities: "true",

},
function(data, status){
    alert("Data: " + data + "\nStatus: " + status);
});
Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
0

There are a few ways.

If you want to do a formal POST, like a form submit, you can construct a form element on your page and submit it. There is a good example of how to do that in this post: JavaScript post request like a form submit

Otherwise, you can make use of AJAX, which is an asynchronous HTTP request standard, which can be done with vanilla JavaScript or by using a third-party library like JQuery. Mozilla has a great resource for learning how to use AJAX at this link: https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started

The Velcromancer
  • 437
  • 3
  • 10
0

You can also use this: https://github.com/floscodes/JS/blob/master/Requests.js

You can easily send a http-Request. Just use:

HttpRequest("https://example.com", method="post", data="yourkey=yourdata");

That's it! It should even work if the site is CSRF-protected.

Or just send a GET-Request by using

HttpRequest("https://example.com", method="get");
Florian
  • 17
  • 2