Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

Posted on by Microsoft Employee

Hi All,

We need to Send Data from CRM  and to Perform Submit Button Automatically with this data on External Application.

I have tried the same request call from Console Application its working fine.

Am working on Dynamics365 - Onpermises.

But it's not working in either Custom Action or Plugin. It's Crashing at GetRequestStream() when we try to Debug.

facing Issue in Custom Action . Code used in Custom Action like Below..

HttpWebResponse httpWebResponse = null;

Stream requestStream = null;

Stream responseStream = null;              

var req = (HttpWebRequest)WebRequest.Create("http://xxxxx/form.do");

var postData = "agnCI=8";

   postData += "&agnFN=DOI-2-Save";

   postData += "&agnSUBSCRIBE=1";

var data = Encoding.ASCII.GetBytes(postData);

req.Method = "POST";

req.ContentType = "application/x-www-form-urlencoded";

req.ContentLength = data.Length;

requestStream = req.GetRequestStream();

requestStream.Write(data, 0, data.Length);

requestStream.Close();

httpWebResponse = (HttpWebResponse)req.GetResponse();

var responseString = new StreamReader(httpWebResponse.GetResponseStream()).ReadToEnd();

 Can anyone help on my request?

Thanks,

Shiva K

*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

    Hi Shiva,

    Kindly verified my answer if its helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

    Thank You Goutam, The Code have written is Working Fine .. Issue with External Application Mandatory Fields .. Now i have taken care of those things..

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

    Hi Shiva ,

    Could you please try rewrite your code  like below. I have tested ,this is working code from CRM . 

    And also try to make a log , or enable trace so that you can understand which line its failing.

                    var webrequest = (HttpWebRequest)System.Net.WebRequest.Create("http:\\testURL");
                    using (var response = webrequest.GetResponse())
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {                   
                        var result = reader.ReadToEnd();                   
                        var serializer = new JavaScriptSerializer();
                        myClassdata pa = serializer.Deserialize<myClassdata>(result);
                       
                    }
    

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

    Thank you All... Traced the Error , Its because of Validations at External Site .. Where Email Address is Mandatory to submit the form.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

    Plugin Profiler doesn't work fine with external calls. Try to use Tracing instead for troubleshooting.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

    {  "@odata.context":"xxxx.com/.../v8.1$metadata#Microsoft.Dynamics.CRM.XRMEMMCustomActionResponse","JSONOutput":"Error - Step 2!"

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

    Hi David,

    Getting Response Back as Error 2! ... And Status Code is Success.

    But We debug the Code using Plugin Profiler.. it Crashing the debbuger at

    requestStream = req.GetRequestStream();

    1)Yes Plugin Deployed in the Sandbox.

    2)yes its external URL on a standard Http Port.

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: POST Data to External Html Form Data from Custom Action using HTTPWebRequest POST Not allowing

    What error do you get ?

    And a couple more questions:

    • Is the plugin deployed in the sandbox or not, and does it make a difference if you change this ?
    • Is the external url on a standard http port (80 or 443), or a different port

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans