How to call a PHP Script from ASP.NET C# and View Its response?

Hi guys,
I was wondering on net abt , how to call a PHP Script from ASP.NET C#, then found a simple solution.
Actually, Its nothing but calling any other ASP.NET C# file.
The script is as follow:
Basically I wanted to send User Id and Account ID and then process the table:

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(“http://rover.geodesic.net/wcv1/php/ProcessTrans.php?userid=” + item.Value + “&accountid=” + item.Key + “&type=stock”);

// Set the ‘Timeout’ property in Milliseconds.
myRequest.Timeout = 600000;//10 mintutes
myRequest.Method = “GET”;
HttpWebResponse newStream = (HttpWebResponse)myRequest.GetResponse();

if ((newStream.ContentLength > 0))
{
System.IO.StreamReader str = new System.IO.StreamReader(newStream.GetResponseStream());
Response.Write(str.ReadToEnd());
if (str != null) str.Close();
}

The small changes I did was, I multi threaded the process, as i was taking more time to execute the PHP page “ProcessTrans.php”;
In above example, Data has been sent in “GET”
If you want to Post Data to remote Web Page using HttpWebRequest :

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(“http://rover.geodesic.net/wcv1/php/ProcessTrans.php?userid=” + item.Value + “&accountid=” + item.Key + “&type=stock”);
request.Method = “POST”;
request.ContentLength = data.Length;
request.ContentType = “application/x-www-form-urlencoded”;
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
response.Close();
Response.Write(tmp);
}

It might not work if the site you’re trying to stream is protected by authentication. If it’s Windows/NTLM Authentication and your account has privileges on the site, try using:
request.Credentials = CredentialCache.DefaultCredentials;
after the create request.

Ref: http://www.worldofasp.net/tut/WebRequest/Working_with_HttpWebRequest_and_HttpWebResponse_in_ASPNET_114.aspx

regards,

Advertisements

62 responses to this post.

  1. thanks.very good blog and very good share.

  2. humm, that awesome post which i was looking for.

  3. Simply a smiling visitant here to share the love (:, btw great layout. “Make the most of your regrets… . To regret deeply is to live afresh.” by Henry David Thoreau.

  4. An amazing article, thanks for the writing.

  5. Great info it is without doubt. My girlfriend has been waiting for this info.

    • This blog post was the Research activity by mine while working over a Media player application which was designed in ASP.net and back end was in PHP. (actually media player was supposed to get a list of playtracks from php file). then after i thought to public this..

  6. I simply needed to thank you so much again. I’m not certain the things I might have sorted out without the type of suggestions provided by you directly on such theme. It became a horrifying difficulty in my opinion, however , observing your specialised approach you treated the issue made me to weep for happiness. Now i’m happy for the advice as well as hope that you know what a great job you’re providing instructing some other people all through your webblog. Most probably you haven’t met any of us.

  7. Thank you a lot for providing individuals with such a brilliant chance to read critical reviews from this blog. It’s always very fantastic and as well , stuffed with fun for me personally and my office co-workers to search your blog minimum thrice every week to study the new guides you have. And lastly, I am also usually happy concerning the special knowledge served by you. Some 2 points on this page are in reality the most effective we have all had.

  8. Hello there! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone. I’m trying to find a template or plugin that might be able to resolve this issue. If you have any suggestions, please share. Thanks!

  9. I like the helpful information you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite certain I’ll learn plenty of new stuff right here! Good luck for the next!

  10. Simply desire to say your article is as astounding. The clearness in your post is just excellent and i can assume you’re an expert on this subject. Well with your permission let me to grab your feed to keep updated with forthcoming post. Thanks a million and please keep up the enjoyable work.

  11. I adored your useful post. super contribution. I hope you produce more. I will carry on watching

  12. Hi, i feel that i saw you visited my website thus i got here to “go back the favor”.I’m attempting to find issues to enhance my site!I assume its ok to use some of your ideas!!

  13. salutations from over the world. interesting article I must return for more.

  14. I would like to show thanks to you just for bailing me out of such a scenario. After looking throughout the internet and getting thoughts which were not beneficial, I assumed my life was over. Existing devoid of the approaches to the difficulties you have resolved by means of your entire report is a serious case, as well as the ones that would have in a negative way damaged my entire career if I hadn’t discovered the website. Your actual knowledge and kindness in dealing with all areas was priceless. I am not sure what I would have done if I had not come upon such a solution like this. I’m able to at this point look forward to my future. Thank you so much for this professional and sensible guide. I will not be reluctant to suggest your web page to anyone who should receive support about this problem.

  15. I have observed that costs for online degree gurus tend to be a terrific value. For example a full College Degree in Communication in the University of Phoenix Online consists of Sixty credits at $515/credit or $30,900. Also American Intercontinental University Online offers a Bachelors of Business Administration with a entire education course requirement of 180 units and a worth of $30,560. Online studying has made taking your education far more easy because you can earn your current degree from the comfort of your home and when you finish from office. Thanks for other tips I’ve learned through the site.

  16. Thank you, sis!

  17. Terrific examples! enjoy the operate on the MGM web site.

  18. Not bad, but Solomon is not free.

  19. Awesome list Eric, among this good collection i like Color Touch Effects.thanks

  20. Could you email me with a few hints & tips about how you made this blog look this cool , I would be thankful.

  21. An cool post right there mate ! Cheers for posting .

  22. Is it alright to insert part of this in my web site if I submit a reference point to this webpage?

  23. An interesting blog post there mate ! Cheers for posting !

  24. Do you might have a spam issue on this website; I also am a blogger, and I was questioning your scenario; weve got developed some good techniques and were looking to trade solutions with other people, be certain to shoot me an e-mail if interested.

  25. How come you dont have your web site viewable in wap format? Can not see anything in my Droid.

  26. It seems to me that this web site doesnt load in a Motorola Droid. Are other folks having the exact same issue? I enjoy this web site and dont want to have to miss it any time Im gone from my computer.

  27. Nearly all of the opinions on this particular web site dont make sense.

  28. Just to let you know your webpage looks a little bit strange in Safari on my notebook using Linux .

  29. pretty beneficial material, in general I picture this is worthy of a book mark, many thanks

  30. When are you going to post again? You really entertain me!

  31. You ought to really moderate the commentary on this website

  32. I believe one of your current advertisements caused my web browser to resize, you may well want to place that on your blacklist.

  33. You ought to really moderate the comments on this site

  34. Amazing article, thank you, I will bookmark you later!

  35. Dude! This blog is sick! How did you make it look like this !

  36. Im getting a small issue. I cant get my reader to pick-up your feed, Im using bing reader by the way.

  37. I love this website layout ! How did you make it? Its really cool!

  38. really useful stuff, on the whole I imagine this is worthy of a book mark, thank you

  39. If you dont mind, exactly where do you host your web site? I am looking for a good quality web host and your site appears to be fast and up almost all the time

  40. Jesus Christ there is a great deal of spammy comments on this web page. Have you ever before believed about attempting to get rid of them or installing a plugin?

  41. Cool post . Thanks for, commenting on my blog dude. I will message you again! I did not realise that!

  42. Unquestionably believe that which you stated. Your favorite reason seemed to be on the web the easiest thing to be aware of. I say to you, I definitely get irked while people consider worries that they just don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks

  43. Unquestionably imagine that that you said. Your favorite justification appeared to be on the internet the simplest factor to remember of. I say to you, I definitely get annoyed even as folks think about worries that they just don’t know about. You managed to hit the nail upon the top as neatly as outlined out the whole thing without having side effect , other people could take a signal. Will likely be again to get more. Thanks

  44. Title…

    I am continually looking online for articles that can facilitate me. Thx!…

  45. Hello there, You have done an excellent job. I’ll certainly digg it and personally suggest to my friends. I’m sure they will be benefited from this site.

  46. can you let me add this article on my site and blogs , sure all the credit will be yours with your name on it , as well as the excellent reviews some other people will write , will help you with your ranking .

  47. How to call a PHP Script from ASP.NET C# and View Its response?…

    Someone necessarily help to make severely articles I’d state. That is the first time I frequented your website page and up to now? I amazed with the research you made to make this particular post amazing. Fantastic job!…

  48. How to call a PHP Script from ASP.NET C# and View Its response?…

    Someone necessarily help to make severely articles I’d state. That is the first time I frequented your website page and up to now? I amazed with the research you made to make this particular post amazing. Fantastic job!…

  49. I could not resist commenting. Perfectly written!

  50. more information…

    […]s digital kitchen scales are the stuff that i always use on my kitchen when i k2[…]…

  51. useful source…

    […]y Sometimes your blog is loading slowly, better find a better host.,~-`, Hmmâ ru[…]…

  52. I located what I used to be searching for. wonderful write-up, many thanks

  53. Normally I do not learn article on blogs, however I would like to say that this write-up very forced me to check out and do it! Your writing style has been amazed me. Thank you, very great article.

  54. Too many times I passed over this blog, and that was a mistake. I’m pleased I will be back!

  55. Title…

    With havin so much content and articles do you ever run into any problems of plagorism or copyright violation? My site has a lot of unique content I’ve either written myself or outsourced but it seems a lot of it is popping it up all over the web with…

  56. Recently, I did not give lots of consideration to leaving comments on weblog webpage posts and also have placed responses even much much less.

  57. I was extremely pleased to discover this website. I wanted to thank you for your time for this particularly wonderful read!! I definitely liked every little bit of it and I have you saved to fav to check out new information on your website.

  58. Heya i’m for the first time here. I came across this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you aided me.

  59. I love it when individuals get together and share thoughts. Great website, keep it up!

  60. I dugg some of you post as I cogitated they were very beneficial extremely helpful

Comments are closed.

%d bloggers like this: