gpt4 book ai didi

php - iOS HTML POST 请求

转载 作者:行者123 更新时间:2023-11-30 13:23:29 24 4
gpt4 key购买 nike

我正在尝试重新创建 this iOS 上的页面。我需要发送搜索参数的 HTML POST 请求如下:

<FORM ACTION="pw_pub_sched.p_listthislist" METHOD="post">

使用Rob's answer here我能够创建以下 HTTP POST 请求的设置:

@IBAction func testHTTPPost(sender: AnyObject) {
let request = NSMutableURLRequest(URL: NSURL(string: "https://banner.sbcc.edu/PROD/pw_pub_sched.p_listthislist")!)
request.HTTPMethod = "POST"
let postString = "TERM=201730&TERM_DESC=Fall 2016&sel_subj=dummy&sel_day=dummy&sel_schd=dummy&sel_camp=dummy&sel_ism=dummy&sel_sess=dummy&sel_instr=dummy&sel_ptrm=%&level=CR"
request.HTTPBody = postString.dataUsingEncoding(NSISOLatin1StringEncoding)
request.HTTPShouldHandleCookies = true
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
(data, response, error) in

guard error == nil && data != nil else { // check for fundamental networking error
print("error=\(error)")
return
}

if let httpStatus = response as? NSHTTPURLResponse where httpStatus.statusCode != 200 { // check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(response)")
}

let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("responseString = \(responseString)")
}
task.resume()

}

但是我每次都会收到 404 错误。这是输出:

statusCode should be 200, but is 404
response = Optional(<NSHTTPURLResponse: 0x7f8e398d2410> { URL: https://banner.sbcc.edu/PROD/pw_pub_sched.p_listthislist } { status code: 404, headers {
Connection = "Keep-Alive";
"Content-Length" = 215;
"Content-Type" = "text/html; charset=iso-8859-1";
Date = "Fri, 27 May 2016 19:23:23 GMT";
"Keep-Alive" = "timeout=5, max=100";
Server = "Oracle-Application-Server-11g";
} })
responseString = Optional(<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /PROD/pw_pub_sched.p_listthislist was not found.</p>
</body></html>
)

当我尝试直接转到 https://banner.sbcc.edu/PROD/pw_pub_sched.p_listthislist 时在我的浏览器中我也出现了 404 错误。只有使用搜索页面上的提交按钮才能成功查看结果页面。然而,我尝试直接向搜索页面发出请求,并且还收到了 404 错误,这让我相信这是我的代码。我应该在其他地方发送此请求吗?为什么除非我浏览搜索页面,否则该页面似乎不存在?

最佳答案

问题是我没有通过 POST 请求发送所有必需的参数。

感谢@MarcB的帮助

关于php - iOS HTML POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37490995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com