我正在使用以下代码使用 API 将条目发布到 Wufoo.com。代码中没有错误,并且正在以正确的形式创建一个新条目。唯一的问题是新记录的所有字段都是空白的。任何人都可以检查此代码并告诉我我在这里做错了什么。谢谢你的帮助!!!!
string url = "https://cssoft.wufoo.com/api/v3/forms/registration-form/entries.json";
string postdata = "{\"Field1\":\"Anshuman\",\"Field3\":\"3216549870\":\"Field4\":\"test@new.com\"}";
byte[] byteArray = Encoding.UTF8.GetBytes(postdata);
WebRequest myReq = WebRequest.Create(url);
string username = "3QNW-MXE2-O74M-RUC6";
string password = "mfs802r0uokbfd";
string usernamePassword = username + ":" + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
myReq.Credentials = mycache;
myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
myReq.ContentType = "multipart/form-data";
myReq.Method = "POST";
myReq.ContentLength = byteArray.Length;
Stream dataStream = myReq.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
Response.Write(content);