Domanda

this is what i have

using Windows.Web.Http;
using Windows.Web.Http.Headers;

public async static Task<bool> FormPost(List<KeyValuePair<string, string>> varvaluepair, string hosturl)
{
    try
    {
        Uri cURI;
        if (Uri.TryCreate(hosturl, UriKind.Absolute, out cURI) && (cURI.Scheme == "http" || cURI.Scheme == "https"))
        {
            var client = new HttpClient();
            client.DefaultRequestHeaders.UserAgent.ParseAdd("ie");
            client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");

            var content = new HttpFormUrlEncodedContent(varvaluepair);
            content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded");

            var response = await client.PostAsync(cURI, content);
            if (response.IsSuccessStatusCode)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    catch (Exception ex)
    {
        return false;

this is what I got from response :

{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 2, Content: Windows.Web.Http.HttpStreamContent, Headers:
{
  Connection: keep-alive
  Server: nginx admin
  Date: Sun, 11 May 2014 15:46:32 GMT
}{
  Content-Length: 335
  Content-Type: text/html; charset=iso-8859-1
}}  Windows.Web.Http.HttpResponseMessage

my host receive the submit value and thing works fine except for the response of 404 and the funcion returning a false instead of true.

This is how I send:

string tmpAddress = "http://www.somewhere.com";
var tmpData = new List<KeyValuePair<string, string>>
{
    new KeyValuePair<string, string>("Name", "Jibah xxxxxxxxxxxx"),
    new KeyValuePair<string, string>("Email", "jibah.kxxxxx@xxxx.com"),
    new KeyValuePair<string, string>("Feedback", "Test submission to see the response"),
    new KeyValuePair<string, string>("form_tools_form_id", "225")
};
bool tmpResult = await FormPost(tmpData, tmpAddress);

and the result from the Formtool website (I cannot post image) the image capture

Excuse my English. thanks.

È stato utile?

Soluzione

I'm not sure this is the correct way for show my finding (someone please correct me, correct this answer)

Its not in the C# code. The response is not what PostAsync send but what was sent by the service called. The service works fine for receiving but returning a redirect page that does not exist. This is Formtool issue.

There's a setting in Formtool to return a redirect URL when form is submitted and received by Formtool. The redirect URL set in Formtool was indeed a page that does not exist, hence the 404.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top