【发布时间】:2020-02-13 21:46:46
【问题描述】:
我正在尝试在量角器中进行 http 发布。 http.post 的状态处于挂起状态,不返回任何响应。
我在specDone下的onPrepare函数中调用一个方法:
jasmine.getEnv().addReporter({
specDone: function(result) {
if (result.status == "failed") {
browser.getCapabilities().then(function(caps) {
var browserName = caps.get("browserName");
browser.takeScreenshot().then(function(png) {
var stream = fs.createWriteStream(
"./reports/screenshots/" +
browserName +
"-" +
result.fullName +
".png"
);
stream.write(new Buffer(png, "base64"));
stream.end();
});
});
}
new PortalData().PushDataToPortal("");
}
});
从onPrepare调用下面的函数,API从body中获取参数。我正在使用 protractor-http-client 包进行 API 调用。
export class PortalData {
public PushDataToPortal(result) {
const http: HttpClient = new HttpClient();
const LogFilePathInSharedLocation =
"\\\\10.101.101.11\\temp\\DocStar\\Automation\\TestLogs\\Logs.txt";
http
.post(
someurl,
LogFilePathInSharedLocation,
{ "Content-Type": "application/x-www-form-urlencoded" }
)
.then((response: ResponsePromise) => {
console.log(response);
});
}
请指教。谢谢!
【问题讨论】:
-
尝试从邮递员那里点击那个 Http 帖子。如果它不起作用,请发布您完整的 Http.post 调用格式。
-
它从邮递员那里工作。我的邮政编码在上面更新。 http .post( someurl, LogFilePathInSharedLocation, { "Content-Type": "application/x-www-form-urlencoded" } ) .then((response: ResponsePromise) => { console.log(response); });
-
尝试这个问题的解决方案:stackoverflow.com/questions/21689089/…
标签: protractor