0

以下のコードを使用して、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);
4

1 に答える 1

2

このコードスニペットを試してみてください..

    string url = "https://cssoft.wufoo.com/api/v3/forms/registration-form/entries.json";
    string APIKey = "3QNW-MXE2-O74M-RUC6";
    string Hashcode = "mfs802r0uokbfd";
    string usernamePassword = APIKey + ":" + Hashcode;

    // Prepare web request...
    HttpWebRequest myReq =
          (HttpWebRequest)WebRequest.Create(url);
    CredentialCache mycache = new CredentialCache();
    mycache.Add(new Uri(url), "Basic", new NetworkCredential(APIKey, Hashcode));
    myReq.Credentials = mycache;
    myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));

    ASCIIEncoding encoding = new ASCIIEncoding();
    string postData = "Field1=Anshuman&Field3=3216549870&Field4=test@new.com";
    byte[] data = encoding.GetBytes(postData);


    myReq.Method = "POST";
    myReq.ContentType = "application/x-www-form-urlencoded";
    myReq.ContentLength = data.Length;
    Stream newStream = myReq.GetRequestStream();

    // Send the data.
    newStream.Write(data, 0, data.Length);
    newStream.Close();

乾杯!!これはあなたがしようとしていることをあなたの仕事にします..

于 2014-11-20T12:30:30.543 に答える