0
我花了很多小時試圖解決這個問題,我自己也找不到解決方案。XML HTTP請求Jodel
這是我的jodelclient對象內的一個函數。
this.sendPost = function(JodelPost)
{
var httpRequest = new XMLHttpRequest(); //create new httpRequest
httpRequest.onreadystatechange = function (data) //This is the function that gets called when you recieve the server response
{
console.log(data); //Prints out the server response
}
var url = 'https://api.go-tellm.com/api/v2/posts/?'; //BaseUrl for jodel api
httpRequest.open('POST', url+JSON.stringify(JodelPost));
httpRequest.setRequestHeader('Authorization', 'Bearer ' + this.token); //For a valid authirazation
httpRequest.send(); //send it flying!
};
來自服務器的響應是
「POST https://api.go-tellm.com/api/v2/posts/ 400(錯誤請求)?」
和
「缺少必需的屬性:位置」
這是對JodelPost變量進行字符串化的結果示例。
{
"color": "FFBA00",
"location": {
"city": "Uppsala",
"country": "46",
"loc_accuracy": 0,
"loc_coordinates": {
"lat": "68.805532",
"lng": "2.943903"
},
"name": "Uppsala"
},
"message": "HelloWorld"
}
當我試圖解決這個我自己,我發現這個github上庫做同樣的事情,但在Python。這可能是一些有用的信息。
提前感謝!我很新這個簡單的解釋讚賞。
太謝謝你了! – Shroom
不客氣。快樂編程! – stevenelberger