我一直在努力寻找如何编写一个云函数,该函数可以对需要用户名和密码的另一台服务器进行POST调用...
我迅速拥有了原始代码:
NSURL *url = [NSURL URLWithString:"https://myserver.com/mypath/"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *data = [NSString stringWithFormat:service_request, myDevice, myPath];
[request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
provisionDeviceConnection = [NSURLConnection connectionWithRequest:request delegate:self];
[provisionDeviceConnection start];
到目前为止,我的Cloud Function中已有此功能:
Parse.Cloud.define("getMyDevice", function(request, response){
var service_request = "<request version=\"1.0\"><file_system cache=\"false\"><targets><device id=\"xxx\"/></targets><commands><get_file path=\"myfile.json\"/></commands></file_system></sci_request>";
return Parse.Cloud.httpRequest({
method: "POST", url: "https://MYSERVER.COM/MYPATH/", headers: { },
body: service_request
}).then(function(httpResponse) {
response.success("Done Http Request!");
}, function(httpResponse) {
response.error('request failed with response code ' + httpResponse.status);
});
});
不确定如何/在何处使用USERNAME和PASSWORD
我尝试了其他选项,但出现错误400。不确定是否应该像这样使用主体...
任何帮助将不胜感激!