Last active
May 24, 2019 12:36
-
-
Save Hawksbillcat/569bde96839787d605f3964bb10f0a16 to your computer and use it in GitHub Desktop.
post in httpclient?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let url = "http://@" + this.sRouterIP + "/config_macfilter_app.php"; | |
let mac:string=("1c:b0:94:ae:0e:1f").toLocaleUpperCase(); | |
let s_body=JSON.stringify({body:"action=app_block&interface=wifi0&mac=" + encodeURIComponent(mac)}) | |
let formdata = new FormData(); | |
formdata.append("body", s_body) | |
let requestOptions: Object = { | |
//headers: new HttpHeaders().set('Content-Type','application/x-www-form-urlencoded')//not works | |
headers: new HttpHeaders().set('Content-Type','application/json'),//not works | |
responseType: 'text' | |
} | |
this.http.post(url,formdata,requestOptions).subscribe((res:any)=>{//put formdata nor s_body object is not working | |
console.log(res) | |
}) | |
/////////////////////////WORKS XMLHTTPREQUEST | |
let sIP = this.sRouterIP; | |
let url = "http://@" + sIP + "/config_macfilter_app.php"; | |
let sBody = "action=app_block&interface=wifi0&mac=" + encodeURIComponent(mac); | |
let request = new XMLHttpRequest(); | |
request.open("POST", url,true); | |
//request.timeout = 30000; | |
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
request.onreadystatechange = () => { | |
if (request.readyState == 4 && request.status == 200) { | |
if (!this.ValidateResponseText(request.responseText)) { | |
this.LoadingFailed(); | |
this.CheckConnection(); | |
} | |
} | |
} | |
request.send(sBody); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this body on your httpClient request :
this.http.post(url,body,requestOptions).subscribe((res:any)=>{ console.log(res) })