Is there a way to reject pending request programmatically, well i don't see any api for that so any yammer expert our there to help?
From Chrome developer tools I see this is the request send by Yammer UI.
https://www.yammer.com/****/join_requests/968249/deny
Code we have used:
WebRequest request = WebRequest.Create("https://www.yammer.com/****/join_requests/968249/deny");
request.Method = "POST";
string postData = "userId=" + userId;
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
request.Headers.Add(HttpRequestHeader.Authorization, yammerToken);
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
Error: 404 not found, its obv the api is not there so any solution
Please find the image
There isn't a supported API for doing this.
Related
I am trying to get request auth token by making a post web request to a url. The api expects username/password as credentials in the form-data payload.
When I click the sign-in option on the browser, the network logs show a GET request with HTML as response, followed by a POST request which returns form-data with username/password and request token in payload.
Trying to mock the flow using webrequest, I am doing a simple post request, as the following:
public string HttpPost(string url, string post, string refer = "")
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
// request.CookieContainer = cJar;
request.UserAgent = UserAgent;
request.KeepAlive = false;
request.Method = "POST";
request.Referer = refer;
byte[] postBytes = Encoding.ASCII.GetBytes(post);
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();
StreamReader sr = new StreamReader(response.GetResponseStream());
return sr.ReadToEnd();
}
However, this request only returns the text/HTML markup of the page as the first part of the request of the browser does. How do I get it to run the subsequent POST to fetch the token from the endpoint?
EDIT 1:
Here is the first GET Request:
The token is a CSRF token, what you need to do is find the login form in the html response that you've received with your initial get request, and also to ensure you are storing the cookies set in this response.
You will then need to search within the html response for the hidden input parameter named 'token' next to the username and pw input fields and use the value of that element to compose your post request.
Doing this programmatically is possible with some regex or the htmlagilitypack to extract that token
Trying to send a web request with some body content. The important part is that I need some data in the body of the post request. My understanding of how to do this is to open a WebRequestStream, and then write the bytes to it, then to close it. This is supposed to be simple. Here is my code:
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create("http://localhost:50203/api/Values");//
request.Method = "POST";
byte[] requestBody = ASCIIEncoding.ASCII.GetBytes(HttpUtility.UrlEncode("grant_type=client_credentials"));
Stream requestBodyStream = request.GetRequestStream();
requestBodyStream.Write(requestBody, 0, requestBody.Length);
requestBodyStream.Flush();
requestBodyStream.Close();
WebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
myString = reader.ReadToEnd();
But the RequestBodyStream.Write method is not sending anything in the body. I know this because I'm running the server side program at the other end.
I also tried to do this with a StreamWriter instead of using a byte stream, and I get the same result. No matter how I do it, there is no content in the body.
My understanding is that closing the stream is what sends the actual data. I also tried adding a Flush() method to the stream.
Why is this method not producing any body?
Add 'ContentType' and 'ContentLength' headers to the request instance:
request.ContentType = "application/json"; // Or whatever you want
request.ContentLength = requestBody.Length;
I am trying to send base64 encoded data through C# WebRequest to php script. Then I receive sent data by file_get_contents("php://input"), when data length is lower than 8 KBs the php code is executed, otherwise it can't be executed. In the other hand php didn't receive the request.
the code C#:
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
// postData is Base64_encoded
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseData = reader.ReadToEnd();
responseData = SecurityUtils.DecryptUrlData(responseData);
reader.Close();
dataStream.Close();
response.Close();
return responseData;
Could any one help?
The below is incorrect (mea culpa). You cannot use enctype=multipart/form-data with php://input. See here
Perhaps you can post your PHP code into your question as well?
Make sure that when you POST from the c# app to your PHP app that you set the enctype to multipart/form-data.
Explanaition
Are you using application/x-www-form-urlencoded or multipart/form-data? There is a good explanation of the differenes here: application/x-www-form-urlencoded or multipart/form-data?
According to the link above, posting data in the application/x-form-urlencoded format will put the body into the URL. Many servers and languages (PHP, Apache) will cut off or throw errors when the URL is greater than 8K. See SO question: What is the maximum length for a URL?
Change the content type for the request
request.ContentType = "text/plain";
Check out php.iniĀ“s post_max_size on the server side
There is a page in remote web-site, where one can enter input values in forms, click a button and get a result in output form.
I want to send a request to the page with filling necessary input forms, submit it and get a result page with output form filled.
All threads with similar topics give the code samples like this:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("http://www.site.com");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = string.Format("inputParam=value");
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
response.Close();
It returns a page with filled input forms, but output field is still blank, like it doesn't do a commit button click.
How can I do a commit from my C# code and receive an html document with output data?
Change the webresponse section to the following;
WebResponse response = request.GetResponse ();
dataStream = response.GetResponseStream ();
StreamReader reader = new StreamReader (dataStream);
string responseFromServer = reader.ReadToEnd ();
I need to write a httpclient to upload a huge file to the server using http. The code
public Stream function()
{
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
request.Method = "POST";
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
return dataStream;
}
Then, I return the dataStream to the caller of this function so that the application keeps writing to the stream using write. Then once done with the writing, GetResponse is called and then the stream is closed. But I get the exception
ProtocolViolationException
at System.Net.HttpWriteStream.Write() while writing to the stream.
Kindly help.
Have you considered using Fiddler to debug the process when using a browser? This is a simple proxy allowing you to inspect http traffic.
The ProtocolViolationException is probably thrown because the request method is GET or HEAD.
You must set the Method to POST like this:
// Set the 'Method' property of the 'Webrequest' to 'POST'.
request.Method = "POST";
See HttpWebRequest.GetRequestStream Method documentation on MSDN.