I am using the below code to post entries to Wufoo.com using the API. There is no error in the code and a new entry is being created under the correct form. The only problem is that the all the fields are blank for the new record. Can any please check this code and tell me what I am doing wrong here. Thanks for your help!!!!
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);
Try this code snippet this should work for you..
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();
Cheers!! This Would do your work what you are trying for..
Related
I am trying to login this site: http://svp.correios.com.br/core/seguranca/entrar.php
But in the end, he still does not login, I am opening the page, capturing the session and trying to login, why in the end, dont work login?
look my code:
string url = "http://svp.correios.com.br/core/seguranca/entrar.php";
//request page to login
HttpWebRequest request01 = (HttpWebRequest)WebRequest.Create(url);
request01.CookieContainer = _cookies;
request01.ContentType = "application/x-www-form-urlencoded";
//load page
HttpWebResponse return01 = (HttpWebResponse)request01.GetResponse();
Stream dataStream = return01.GetResponseStream();
StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("ISO-8859-1"));
//get section
string responseFromServer = reader.ReadToEnd();
String[] rastreamentoCompleto = Regex.Split(responseFromServer, "<section id=\"geral\">\n\t<form id=\"fm1\" action=\"");
String[] retiraFim = Regex.Split(rastreamentoCompleto[1], "\" method=\"post\">\n <div id");
string keySection = retiraFim[0];
//try login
HttpWebRequest request02 = (HttpWebRequest)WebRequest.Create("https://apps.correios.com.br" + keySection);
request02.CookieContainer = _cookies;
request02.Method = "POST";
string postData = "username="+ user + "&password="+ password;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request02.ContentType = "application/x-www-form-urlencoded";
request02.ContentLength = byteArray.Length;
dataStream = request02.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
//check if Logged
HttpWebResponse return02 = (HttpWebResponse)request02.GetResponse();
dataStream = return02.GetResponseStream();
reader = new StreamReader(dataStream, Encoding.GetEncoding("ISO-8859-1"));
responseFromServer = reader.ReadToEnd();
i'm trying to POST large contents, about 13000 Characters. But i keep getting operation timed out. Changing the timeout doesn't help, because it takes a very long time.
Here's my code
string textToSpin = rtbOri.Text; //13000 Characters
string post_data = "api_key=" + api_key + "&article=" + HttpUtility.UrlEncode(textToSpin) + "&lang=" + lang;
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(serviceUri);
request.Credentials = new NetworkCredential("userName", "password");
request.Method = "POST";
request.Timeout = Timeout.Infinite;
byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string reader = new StreamReader(response.GetResponseStream()).ReadToEnd();
rtbSpin.AppendText(reader);
Any idea? thanks
string RegId = "************";
string ApplicationID = "*****";
string SENDER_ID = "***";
var value = "sandeepweb"; //message text box
WebRequest tRequest;
tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post";
tRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", ApplicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
//Data post to the Server
string postData =
"collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message="
+ value + "&data.time=" + System.DateTime.Now.ToString() +
"®istration_id=" + RegId + "";
Console.WriteLine(postData);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse(); dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd(); //Get response from GCM server
tReader.Close(); dataStream.Close();
tResponse.Close();
lblsuccess.Text = sResponseFromServer;
App Crashes When i send any notification. Notifications are sent from Firebase console. Do I need to make some changes in above code?
You can use FireSharp. it uses Firebase REST API behind the scenes and make your queries easy and felxible. You dont have to deal with a large messy code
Push Example:
var todo = new Todo {
name = "Execute PUSH",
priority = 2
};
PushResponse response =await _client.PushAsync("todos/push", todo);
response.Result.name //The result will contain the child name of the new data that was added
I'm trying to get the userID of a Facebook user, I already have the access_token and I use http request to do it. My simple problem is that : I want the user's id but my program just crash... I use WPF, C# Here is my little call :
var url = string.Format("https://graph.facebook.com/me?access_token=" + token + "&response_type=id");
var req = WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
string postData = "'access_token='" + token;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
var stream = req.GetRequestStream();
stream.Write(byteArray, 0, byteArray.Length);
stream.Close();
WebResponse response = req.GetResponse();
aTextBox.Text = ((HttpWebResponse)response).StatusDescription;
stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
Thanks!
Don't use Web Browser for this! You may use HttpWebRequest for that kind of things:
string url = "https://graph.facebook.com/me?access_token=" + token + "&response_type=id";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
Stream receiveStream = response.GetResponseStream ();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
string responseData = readStream.ReadToEnd();
Ive a problem with a code because it work differently if I test it in Visual Studio either I test it on my site.
i am trying to do an autologin on an external web site. If I test it from VS, I am correctly redirected on the external site. From my site i obtain i am redirected to "http://www.MySite.com/cgi-bin/wbc_login/...."!!!!!
The code is the following:
private void MioMetodo(String username, String password)
{
CookieContainer Cookies = new CookieContainer();
Cookie langCookie = new Cookie("pk_lang", "\"italiano\"", "/");
langCookie.Domain = "xxx.yy";
Cookie loginCookie = new Cookie("wc_loginoslimit", "\"" + username + "\"", "/");
loginCookie.Domain = "xxx.yy";
Cookie passwordCookie = new Cookie("wc_passwordoslimit", "\"" + password + "\"", "/");
passwordCookie.Domain = "xxx.yy";
Cookies.Add(langCookie);
Cookies.Add(loginCookie);
Cookies.Add(passwordCookie);
UTF8Encoding encoding = new UTF8Encoding();
String postData = "wc_login=" + username + "&wc_password=" + password + "&limit=0&Avanti=Avanti";
Byte[] data = encoding.GetBytes(postData);
HttpWebRequest myHttpWebRequest = WebRequest.Create("http://xxx.yy/cgi-bin/wbc_login") as HttpWebRequest;
myHttpWebRequest.Method = "POST";
myHttpWebRequest.Referer = "http://xxx.yy/cgi-bin/wbc_login";
myHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
myHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate,sdch");
myHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4");
myHttpWebRequest.Headers.Add(HttpRequestHeader.CacheControl, "max-age=0");
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.CookieContainer = Cookies;
myHttpWebRequest.ContentLength = data.Length;
Stream newStream = myHttpWebRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse myHttpWebResponse = myHttpWebRequest.GetResponse() as HttpWebResponse;
StreamReader streamRead =new StreamReader(myHttpWebResponse.GetResponseStream());
Response.Write(streamRead.ReadToEnd());
streamRead.Close();
myHttpWebResponse.Close();
}
Thanx in advance