我使用JS自动化框架来测试iOS应用程序。在测试过程中,我需要向服务器创建POST请求以向用户提供一些资金,然后验证更改是否反映在UI中。
I use JS automation framework for testing iOS application. In the middle of a test I need to create POST request to server to some money to user and then verify that changes are reflected in UI.
请求如下:wwww.testserver/userAddMoney?user_id=1&amount=999
Request looks like: wwww.testserver/userAddMoney?user_id=1&amount=999
但是要在服务器上进行授权,我需要将特殊参数传递给请求标头:
but to authorize on server I need to pass special parameters to Header of request:
标题: X-Testing-Auth-Secret:kI7wGju76kjhJHGklk76
Headers: X-Testing-Auth-Secret: kI7wGju76kjhJHGklk76
提前致谢!
推荐答案所以基本上你想设置标题一个POST请求。只有在ajax请求时才能执行此操作(您无法为正常的html表单提交请求设置标头)。以下是为ajax请求设置标头的方法:
So basically you want to set the header of a POST request. You can do it only if its an ajax request (You can't set headers for a normal html form submission request). Here is a way to set headers for an ajax request:
var request = new XMLHttpRequest(); request.onreadystatechange= function () { if (request.readyState==4) { //handle response } } request.open("POST", "url", true); request.setRequestHeader("header", "blah blah"); request.setRequestHeader("Accept","text/plain"); request.send("post data");更多推荐
如何使用标头和数据创建到服务器的javascript POST请求
发布评论