【发布时间】:2017-03-31 00:44:08
【问题描述】:
我正在尝试使用 API 来更新在线数据库。
API 由法国网站托管,使用细节很少,没有示例。
这是他们提供的信息
The query must be sent as a "multipart / form-data" html form using the "POST" method.
Input parameters:
ssid : (type "text") user's ScreenScraper identifier
sspassword : (type "text") ScreenScraper password of the user
gameid : (type "text") numerical identifier of the game on ScreenScraper
or
romid ( "text") numeric ID of the Roma on ScreenScraper
to propose a textual info:
modiftypeinfo ( "text") type of information sent (see list "modiftypeinfo")
modifregion ( "text"
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META http-equiv="content-language" content="fr">
<title></title>
</head>
<body>
<form name="myform" id="myform" method="post" enctype="multipart/form-data" action="https://www.screenscraper.fr/api/botProposition.php?ssid=xxx&sspassword=yyy">
<input type="text" name="gameid" value="3">
<input type="text" name="modiftypeinfo" value="description">
<input type="text" name="modifregion" value="">
<input type="text" name="modiflangue" value="fr">
<input type="text" name="modifversion" value="">
<input type="text" name="modiftexte" value="ici, le synopsis du jeu ! ne pas valider, c'est un test ;)">
<input type="text" name="modifsource" value="botProposition / source de l'info">
<input type="submit" value="envoyer">
</form>
<script>
document.getElementById("myform").submit();
</script>
</body>
</html>
这是我整理的代码:
Sub Post_Detail()
Dim xmlhttp As Object, response As String, SendString As String
Set xmlhttp = CreateObject("MSXML2.XMLHTTP.6.0")
'~~> Indicates that page that will receive the request and the type of request being submitted
xmlhttp.Open "POST", "https://www.screenscraper.fr/api/botProposition.php?ssid=xxx&sspassword=yyy", False
'~~> Indicate that the body of the request contains form data
xmlhttp.setRequestHeader "Content-Type", "text/html; charset=UTF-8"
xmlhttp.setRequestHeader "enctype", "multipart/form-data"
'~~> Send the data as name/value pairs
SendString = "&type=text&name=gameid&value=185882"
SendString = SendString & "&type=text&name=modiftypeinfo&value=genres"
SendString = SendString & "&type=text&name=modiftexte&value=Sports"
SendString = SendString & "&type=submit&value=envoyer"
Debug.Print SendString
xmlhttp.send SendString
response = xmlhttp.responseText
MsgBox response
Set xmlhttp = Nothing
End Sub
我不确定如何处理这部分:说明中的form name="myform" id="myform",我不确定我通过构建字符串的请求是否接近正确。
您将无法在没有登录的情况下运行,它会返回密码无效错误。
【问题讨论】:
-
HTML 表单的名称和 ID 不会随提交一起发送,因此您可以将其省略。您唯一需要的是输入的名称和值(因此也不要使用“type=text”)。如果您有包含该表单的页面,您可以使用(例如)Fiddler 或浏览器的开发者工具来查看提交表单时发送的内容。