如何通过HTTP发布到Google文档生成的表单 [英] How to HTTP Post to Google Docs generated form
本文介绍了如何通过HTTP发布到Google文档生成的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以编程方式填写在线表单与发布到Google文档生成的表单(例如Google Spreadsheet Live表单)有什么区别?
我尝试了以下操作,但均未成功:
What is the difference in programmatically filling in an online form versus posting to a Google-documents-generated form such as a Google Spreadsheet Live Form?
I tried the following with no success:
WebRequest req = WebRequest.Create(URI);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
string postData = "entry.0.single=ABCD&entry.1.single=EFGH&submit=click";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
req.ContentLength = byteArray.Length;
Stream os = req.GetRequestStream ();
os.Write (byteArray, 0, byteArray.Length);
os.Close ();
响应使我回到了Google表单.
:confused:
and the response just gets me back to the Google form.
:confused:
推荐答案
我对此有很多麻烦,但是在查看了google代码并使用Wireshark嗅探HTTP Post之后,我能够获得此信息-一个很好的起点(但是我在一些更复杂的测试表单中收到405错误..不确定为什么)
I had alot of trouble with this, but after looking at the google code and sniffing the HTTP Post with Wireshark i was able to obtain this- a good starting point (but I was getting 405 errors on some of my more complicated test forms.. not sure why)
Imports System.Web
Imports System.Net
Imports System.IO
Imports System.Text
Public Class Form1
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim address As Uri
Dim appId As String
Dim context As String
Dim query As String
Dim data As StringBuilder
Dim byteData() As Byte
Dim postStream As Stream = Nothing
''''Dim myHttpUtility As HttpUtility
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
post()
End Sub
Sub post()
address = New Uri("http://googleform")
'' Create the web request
request = DirectCast(WebRequest.Create(address), HttpWebRequest)
'' Set type to POST
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
'' Create the data we want to send
appId = "ss-form"
data = New StringBuilder()
data.Append("entry.0.single=" + HttpUtility.UrlEncode(BrandBox.Text))
data.Append("&entry.2.single=" + HttpUtility.UrlEncode(ModelBox.Text))
data.Append("&entry.3.single=" + HttpUtility.UrlEncode(ModelStringBox.Text))
'' Create a byte array of the data we want to send
byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())
'' Set the content length in the request headers
request.ContentLength = byteData.Length
'' Write data
Try
postStream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
Finally
If Not postStream Is Nothing Then postStream.Close()
End Try
Try
'' Get response
response = DirectCast(request.GetResponse(), HttpWebResponse)
'' Get the response stream into a reader
reader = New StreamReader(response.GetResponseStream())
'' Console application output
MessageBox.Show(reader.ReadToEnd())
Finally
If Not response Is Nothing Then response.Close()
End Try
End Sub
End Class
-d www.chromableedstudios.com [ ^ ]
-dwww.chromableedstudios.com[^]
嗨
非常感谢您对此进行调查.我回家后就去试试.
我注意到数据字符串不包含提交"吗?在搜寻答案时,我发现了一些建议,包括pageNumber backupCache并在数据字符串中提交.
今天晚上我会尝试一下.
干杯
Hi
Thanks so much for looking into this. I''ll give this a go when I get home.
I notice that the data string didn''t include ''submit''? In googling for answers, I found some suggestions to include pageNumber backupCache and submit in the data string.
I''ll try this out this evening.
Cheers
这篇关于如何通过HTTP发布到Google文档生成的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文