Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
api:internet [2019/06/12 05:26]
jacky_wang [Internet API]
api:internet [2019/06/15 09:24]
payonel
Line 3: Line 3:
 This library wraps functionality of Internet cards. Also see the [[component:​internet|Internet Component]] for more low level functionality (such as querying availability of HTTP and TCP functionality). This library wraps functionality of Internet cards. Also see the [[component:​internet|Internet Component]] for more low level functionality (such as querying availability of HTTP and TCP functionality).
  
-- `internet.request(url:​ string[, data: string or table[, headers: table]]): function` ​  +- `internet.request(url:​ string[, data: string or table[, headers: table[, method: string]]]): function` ​  
-  Sends an HTTP request to the specified URL, with the specified POST data, if any. If no data is specified, a GET request will be made. The POST data can be in one of two formats: if it's a string, it will be sent as-is. If it's a table, it will be converted to a string by assuming that each key is the name of a POST variable, and it's associated value is the value for that variable. ​Sofor example +  Sends an HTTP request to the specified URL, with the specified POST data, if any. If no data is specified, a GET request will be made. The POST data can be in one of two formats: if it's a string, it will be sent as-is. If it's a table, it will be converted to a string by assuming that each key is the name of a POST variable, and it's associated value is the value for that variable. ​**method** can be explicitly specified to values such as GETPOST, or PUT. Some examples:
   `internet.request(url,​ {some = "​variable",​ another = 1})`  ​   `internet.request(url,​ {some = "​variable",​ another = 1})`  ​
   Will send `some=variable&​another=1`.  ​   Will send `some=variable&​another=1`.  ​
Line 11: Line 11:
   Note that **this method ALSO support HTTPS**. So simply use    Note that **this method ALSO support HTTPS**. So simply use 
   `internet.request("​https://​example.com"​)` to send a request through HTTPS.   `internet.request("​https://​example.com"​)` to send a request through HTTPS.
 +  ​
 +  Example specifying PUT:
 +  `internet.request("​https://​example.com",​ "put data", {}, "​PUT"​)`.
  
 - `internet.socket(address:​string[,​ port:​number]):​table`  ​ - `internet.socket(address:​string[,​ port:​number]):​table`  ​
Line 76: Line 79:
 ----------- -----------
 {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}
 +