簡體   English   中英

相當於PHP Post的Python

[英]Python equivalent to PHP Post

我正在使用舊版系統,以前的程序員已經離開了。 這是他留下的測試,我不知道如何使用Python來模仿他的測試。

這是test.php

var tHost = "10.1.10.123";
var tExiname = "CloudHM TEST123";
var tIncname = "INC012345";
var tHWname = "aa 1111 0";
var tHwattr = "all";
var tStatus = 0;
var tCteatedat = "2016-05-23 12:20:42";
var d = new Date,
tUpdateat = [d.getFullYear(),
             d.getMonth()+1,
             d.getDate()].join('-')+' '+
          [d.getHours(),
           d.getMinutes(),
           d.getSeconds()].join(':');
var arr =  [{ host: tHost, host_name: tExiname, component_type: tHWname, component_status: tStatus, incident_created: tUpdateat }];
var arr2 =JSON.stringify(arr)
$.ajax({
    url: 'http://customer.beenets.net/api/cloudhm/api.php' ,
    type: 'POST',
    data: { params: arr2 },
    success: function(msg) {
        //ShowOutput(msg);
        alert(JSON.stringify(arr, null, 4));
    }
})

我已經嘗試過了。 響應為200 ,但PHP服務器未讀取有效負載

notification_data = [{
            "host": i.host,
            "host_name": i.host_name,
            "incident_created": i.incident_created,
            "component_type": i.component_type,
            "component_status": i.component_status
        }]
        response = requests.post(NOC_BEENETS_URL, data=json.dumps(notification_data))

然后我嘗試將params鍵放在它前面

notification_data = [{
    "params":{
        "host": i.host,
        "host_name": i.host_name,
        "incident_created": i.incident_created,
        "component_type": i.component_type,
        "component_status": i.component_status
    }
}]
response = requests.post(NOC_BEENETS_URL, data=json.dumps(notification_data))

服務器返回我200並再次讀取任何有效載荷。

編輯:

notification_data = [{
        "host": i.host,
        "host_name": i.host_name,
        "incident_created": i.incident_created,
        "component_type": i.component_type,
        "component_status": i.component_status
    }]
r = requests.post(NOC_BEENETS_URL, data = {'params': json.dumps(notification_data)})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM