How to Get Data From PHP C# - c#

I have a Php Script in my Host Which has the link of my new version of my Program,How Can I Get that link From Php? I mean I wanna get that link From Php and Save it in one String.
I Often Use This Code For Doing Something like this:
webbrowser.Nagative("MyPhp Uri");
webbrowser.Document.ExecCommand("SelectAll", false, null);
webbrowser.Document.ExecCommand("Copy", false, null);
Than I Paste it in one Textbox
textbox1.Paste();
But This Way is not Complete way to get data From Php?
Can you help me?

You should use webrequest instead.
I'm not posting a complete solution because I'm pretty sure you will find one as soon as you know what to search for:
using System;
using System.Net;
//create a request object and server call
Uri requestUri = new Uri("MyPhp Uri");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.requestUri);
//set all properties you need for the request, like
request.Method = "GET";
request.BeginGetResponse(new AsyncCallback(ProcessResponse), request);
//handle response
private void ProcessResponse(IAsyncResult asynchronousResult)
{
string responseData = string.Empty;
HttpWebRequest myrequest = (HttpWebRequest)asynchronousResult.AsyncState;
using (HttpWebResponse response = (HttpWebResponse)myrequest.EndGetResponse(asynchronousResult))
{
Stream responseStream = response.GetResponseStream();
using (var reader = new StreamReader(responseStream))
{
responseData = reader.ReadToEnd();
}
responseStream.Close();
}
//TODO: do something with your responseData
}
Please notice: you should definitively add some try/catch blocks.. this is only a short example to point you in the right direction.

Related

How to use get_video_info Youtube

I'm trying to develop a Youtube downloader.I need video mp4 stream urls and im trying to use get_video info check my source code
WebRequest req = HttpWebRequest.Create("https://www.youtube.com/get_video_info?video_id=" + videoid +"&el=embedded&ps=default&eurl=&gl=US&hl=en");
WebResponse webResp = req.GetResponse();
StreamReader sr = new StreamReader(webResp.GetResponseStream(), System.Text.Encoding.UTF8);
string data = sr.ReadToEnd();
sr.Close();
webResp.Close();
This codes always get just a part of data maybe half.After decoding data just looks like this
length_seconds=459&sffb=True&no_get_video_log=1&hl=en_US&vmap=<?xml+version="1.0"+encoding="UTF-8"?><vmap:VMAP+xmlns:vmap="http://www.iab.net/videosuite/vmap"+xmlns:yt="http://youtube.com"+version="1.0"><vmap:AdBreak+breakType="linear"+timeOffset="start"><vmap:AdSource+allowMultipleAds+=+"false"><vmap:VASTData><VAST+version="3.0"><Ad><Wrapper><AdSystem+version="1">YT:AdSense</AdSystem><VASTAdTagURI><![CDATA[https://googleads.g.doubleclick.net/pagead/ads?ad_type=text_image&channel=Vertical_1021+Vertical_1036+Vertical_1408+Vertical_211+Vertical_36+Vertical_590+Vertical_613+afv_overlay+afv_user_id_IO0szsIo5AKIFmbbhfxFqw+afv_user_lundgrenrob+invideo_overlay_480x70_cat10+yt_cid_679125+yt_mpvid_xxV6hpjhJlzWVUm7+yt_no_360+yt_no_3pas+yt_no_ap+yt_no_cp+yt_no_wa+ytdevice_1+ytdevicever_1.20170712+ytel_embedded+ytps_default&client=ca-pub-6219811747049371&dbp=ChZoWFduSWZZN2VpcG9CaWVYWnBPSndBEAEgASgA&description_url=http://www.youtube.com/video/rzkoQFbzmOk&eid=148648206&hl=en&host=ca-host-pub-7533488853144487&ht_id=5547539&loeid=9413138,9422596,9431012,9434289,9441394,9444433,9444893,9450707,9451825,9460350,9463578,9465813,9475121,9475579,9476699,9478199,9478523,9479324,9480114,9480538,9481125,9481317,9482504,9482602,9482851,9483147,9483258,9483501&osd=2&pucrd=CgYIABAAGAA&sdki=18803DAD&url=http://www.youtube.com/video/rzkoQFbzmOk&videoad_start_delay=0&v_p=JY0c2kM=&ytdevice=1&ytdevicever=1.20170712&yt_pt=APb3F2_FMmSD8mG8PMmMq7urTSbmCkJ0Bga4WDpKEQV0vAboVlPPijEHbExGYSXuMBmFcOJpCrpa2LhYnrkbgQbnWXXOarZjCKizS68OiIqOlB2GrZui5-ggUQ6aT7w6CaS_ifnYBnZXHpId9iX76vg6ufeyBrm43Pn8XtzfKSqvqvC1W8CRVv5me3zlMAU8-o1WblaDrL0g1b7SL7ot8DDGof6LRYQvNLPRCMZ6cjjIRMd62t7yetC6yMM2gjL_wZnSM_yKWhGZZgCWLQpIGY40tHARFRtOCCQsri5ttw&yt_vis=0]]></VASTAdTagURI><Impression><![CDATA[https://www.youtube.com/api/stats/ads?ver=2&ns=1&event=2&device=1&content_v=rzkoQFbzmOk&el=embedded&ei=om5qWfj6NYL_WNjYpIAD&devicever=1.20170712&asr=CgA&format=[FORMAT_NAMESPACE]_[FORMAT_TYPE]_[FORMAT_SUBTYPE]&break_type=[BREAK_TYPE]&conn=[CONN]&cpn=[CPN]&lact=[LACT]&m_pos=[MIDROLL_POS]&mt=[MT]&p_h=[P_H]&p_w=[P_W]&rwt=[RWT]&sdkv=[SDKV]&slot_pos=[SLOT_POS]&vis=[VIS]&vol=[VOL]&wt=[WT]&ad_cpn=[AD_CPN]&ad_id=[AD_ID]&ad_len=[AD_LEN]&ad_mt=[AD_MT]&ad_sys=[AD_SYS]&ad_v=[AD_V]&aqi=]]></Impression><Error><![CDATA[https://www.youtube.com/api/stats/ads?ver=2&ns=1&event=5&device=1&content_v=rzkoQFbzmOk&el=embedded&ei=om5qWfj6NYL_WNjYpIAD&devicever=1.20170712&format=[FORMAT_NAMESPACE]_[FORMAT_TYPE]_[FORMAT_SUBTYPE]&break_type=[BREAK_TYPE]&conn=[CONN]&cpn=[CPN]&lact=[LACT]&m_pos=[MIDROLL_POS]&mt=[MT]&p_h=[P_H]&p_w=[P_W]&rwt=[RWT]&sdkv=[SDKV]&slot_pos=[SLOT_POS]&vis=[VIS]&vol=[VOL]&wt=[WT]&ad_cpn=[AD_CPN]&ad_id=[AD_ID]&ad_len=[AD_LEN]&ad_mt=[AD_MT]&ad_sys=[AD_SYS]&ad_v=[AD_V]&blocking_error=[BLOCKING_ERROR]&error_msg=[ERROR_MSG]&ima_error=[IMA_ERROR]&internal_id=[INTERNAL_ID]&error_code=[YT_ERROR_CODE]&aqi=]]></Error><Creatives><Creative><NonLinearAds><TrackingEvents><Tracking+event="close"><![CDATA[https://www.youtube.com/api/stats/ads?ver=2&ns=1&event=4&device=1&content_v=rzkoQFbzmOk&el=embedded&ei=om5qWfj6NYL_WNjYpIAD&devicever=1.20170712&format=[FORMAT_NAMESPACE]_[FORMAT_TYPE]_[FORMAT_SUBTYPE]&break_type=[BREAK_TYPE]&conn=[CONN]&cpn=[CPN]&lact=[LACT]&m_pos=[MIDROLL_POS]&mt=[MT]&p_h=[P_H]&p_w=[P_W]&rwt=[RWT]&sdkv=[SDKV]&slot_pos=[SLOT_POS]&vis=[VIS]&vol=[VOL]&wt=[WT]&ad_cpn=[AD_CPN]&ad_id=[AD_ID]&ad_mt=[AD_MT]&ad_sys=[AD_SYS]&ad_v=[AD_V]&i_x=[I_X]&i_y=[I_Y]&aqi=]]></Tracking></TrackingEvents><NonLinear><NonLinearClickTracking><![CDATA[https://www.youtube.com/api/stats/ads?ver=2&ns=1&event=6&device=1&content_v=rzkoQFbzmOk&el=embedded&ei=om5qWfj6NYL_WNjYpIAD&devicever=1.20170712&format=[FORMAT_NAMESPACE]_[FORMAT_TYPE]_[FORMAT_SUBTYPE]&break_type=[BREAK_TYPE]&conn=[CONN]&cpn=[CPN]&lact=[LACT]&m_pos=[MIDROLL_POS]&mt=[MT]&p_h=[P_H]&p_w=[P_W]&rwt=[RWT]&sdkv=[SDKV]&slot_pos=[SLOT_POS]&vis=[VIS]&vol=[VOL]&wt=[WT]&ad_cpn=[AD_CPN]&ad_id=[AD_ID]&ad_len=[AD_LEN]&ad_mt=[AD_MT]&ad_sys=[AD_SYS]&ad_v=[AD_V]&i_x=[I_X]&i_y=[I_Y]&aqi=[AQI]]]></NonLinearClickTracking></NonLinear></NonLinearAds></Creative></Creatives><Extensions><Extension+type="waterfall"+fallback_index="1"/><Extension+type="activeview"><CustomTracking><Tracking+event="viewable_impression"><![CDATA[https://www.youtube.com/api/stats/ads?ver=2&ns=1&event=11&device=1&content_v=rzkoQFbzmOk&el=embedded&ei=om5qWfj6NYL_WNjYpIAD&devicever=1.20170712&format=[FORMAT_NAMESPACE]_[FORMAT_TYPE]_[FORMAT_SUBTYPE]&break_type=[BREAK_TYPE]&conn=[CONN]&cpn=[CPN]&lact=[LACT]&m_pos=[MIDROLL_POS]&mt=[MT]&p_h=[P_H]&p_w=[P_W]&rwt=[RWT]&sdkv=[SDKV]&slot_pos=[SLOT_POS]&vis=[VIS]&vol=[VOL]&wt=[WT]&ad_cpn=[AD_CPN]&ad_id=[AD_ID]&ad_len=[AD_LEN]&ad_mt=[AD_MT]&ad_sys=[AD_SYS]&ad_v=[AD_V]&aqi=]]></Tracking></CustomTracking></Extension></Extensions></Wrapper></Ad></VAST></vmap:VASTData></vmap:AdSource><vmap:TrackingEvents><vmap:Tracking+event="error"><![CDATA[https://www.youtube.com/api/stats/ads?ver=2&ns=1&event=1&device=1&content_v=rzkoQFbzmOk&el=embedded&ei=om5qWfj6NYL_WNjYpIAD&devicever=1.20170712&break_type=[BREAK_TYPE]&conn=[CONN]&cpn=[CPN]&lact=[LACT]&m_pos=[MIDROLL_POS]&mt=[MT]&p_h=[P_H]&p_w=[P_W]&rwt=[RWT]&sdkv=[SDKV]&slot_pos=[SLOT_POS]&vis=[VIS]&vol=[VOL]&wt=[WT]]]></vmap:Tracking></vmap:TrackingEvents><vmap:Extensions><vmap:Extension+type="YouTube"><yt:BreakProperty+break_type="BREAK_TYPE_PRE_ROLL"/></vmap:Extension></vmap:Extensions></vmap:AdBreak><vmap:AdBreak+breakType="linear"+timeOffset="end"><vmap:AdSource+allowMultipleAds+=+"false"><vmap:AdTagURI><![CDATA[https://www.youtube.com/get_midroll_info?ei=om5qWfj6NYL_WNjYpIAD&m_pos=-1&index=1&token=AHArUmCi7IgSemIU1zQ6mZwxAcXsVLNJRz6p3BHXmckVo5VKctFqc4x6ksXsbH17HJT9kg5rEKPeTdDjb8Futt8whSRi64lqWuqukgtn7FROGCnEcb9nflpkqnys0RH7G3Felht1tx5IPbpnRh6iSc3pfhsvMMPvQRMUmRuozIyIZp7xVwhrQeYReh0leKubfaqXPRTWIGKf2u-2G082rpE8bhBTdY-ZINFWZXRhW3QAe2N9VTy4wbPGvNo7KAQ2qdBIoMJoJ9-LKEkHoensql4QkA8b3tQb9lJylNiD7N6DG4OQM0gGUrTW0xabLI-NLmeGOeRTCKr-&ad_block=[AD_BLOCK]&cpn=[CPN]&lact=[LACT]&tsla=[TSLA]&vis=[VIS]&c=WEB&cver=1.20170712]]></vmap:AdTagURI></vmap:AdSource><vmap:TrackingEvents><vmap:Tracking+event="error"><![CDATA[https://www.youtube.com/api/stats/ads?ver=2&ns=1&event=1&device=1&content_v=rzkoQFbzmOk&el=embedded&ei=om5qWfj6NYL_WNjYpIAD&devicever=1.20170712&break_type=[BREAK_TYPE]&conn=[CONN]&cpn=[CPN]&lact=[LACT]&m_pos=[MIDROLL_POS]&mt=[MT]&p_h=[P_H]&p_w=[P_W]&rwt=[RWT]&sdkv=[SDKV]&slot_pos=[SLOT_POS]&vis=[VIS]&vol=[VOL]&wt=[WT]]]></vmap:Tracking></vmap:TrackingEvents><vmap:Extensions><vmap:Extension+type="YouTube"><yt:BreakProperty+break_type="BREAK_TYPE_POST_ROLL"/></vmap:Extension></vmap:Extensions></vmap:AdBreak><vmap:Extensions><vmap:Extension+type="YouTube"><TrackingDecoration+match="^https?://((([a-z][a-z0-9.-]*\.)?(youtube|corp\.google).com/api/stats/ads)|((www\.)?youtube\.com/pagead/psul))"+headers="device,user"/><TrackingMacro+match="^https?://(secure\-uat\-dpr\.imrworldwide|secure\-gg\.imrworldwide|g\.scorecardresearch)\.com/"+macros="device_id"/><RegexUriMacroValidator><MacroToRegexUris+macro="NIELSEN_DEVICE_ID"><RegexUri+value="^https?://(secure\-uat\-dpr\.imrworldwide|secure\-gg\.imrworldwide|g\.scorecardresearch)\.com/"/></MacroToRegexUris><MacroToRegexUris+macro="COMSCORE_DEVICE_ID"><RegexUri+value="^https?://(secure\-uat\-dpr\.imrworldwide|secure\-gg\.imrworldwide|g\.scorecardresearch)\.com/"/></MacroToRegexUris><MacroToRegexUris+macro="MOAT_INIT"><RegexUri+value="^https?://yts\.moatads\.com"/><RegexUri+value="^https?://yts-testing\.moatads\.com"/><RegexUri+value="^https?://pagead2\.googlesyndication\.com/pagead/gen_204"/></MacroToRegexUris><MacroToRegexUris+macro="MOAT_VIEWABILITY"><RegexUri+value="^https?://[^.]*\.moatads\.com"/><RegexUri+value="^https?://pagead2\.googlesyndication\.com/pagead/gen_204"/><RegexUri+value="^https?://pubads\.g\.doubleclick\.net"/></MacroToRegexUris><MacroToRegexUris+macro="IAS_VIEWABILITY"><RegexUri+value="^https?://pm\.adsafeprotected\.com/youtube"/><RegexUri+value="^https?://pm\.test-adsafeprotected\.com/youtube"/><RegexUri+value="^https?://pagead2\.googlesyndication\.com/pagead/gen_204"/><RegexUri+value="^https?://pubads\.g\.doubleclick\.net"/></MacroToRegexUris><MacroToRegexUris+macro="DV_VIEWABILITY"><RegexUri+value="^https?://e[0-9]+\.yt\.srs\.doubleverify\.com"/><RegexUri+value="^https?://pagead2\.googlesyndication\.com/pagead/gen_204"/><RegexUri+value="^https?://pubads\.g\.doubleclick\.net"/></MacroToRegexUris><MacroToRegexUris+macro="GOOGLE_VIEWABILITY"><RegexUri+value="^https?://pagead2\.googlesyndication\.com"/><RegexUri+value="^https?://pubads\.g\.doubleclick\.net"/><RegexUri+value="^https?://googleads\.g\.doubleclick\.net"/><RegexUri+value="^https?://([a-z0-9]+\.)*youtube\.com"/><RegexUri+value="^https?://ad[\.-]([a-z0-9]+\.){0,1}doubleclick\.net"/><RegexUri+value="^https?://ade\.googlesyndication\.com"/></MacroToRegexUris></RegexUriMacroValidator></vmap:Extension></vmap:Extensions></vmap:VMAP>&encoded_ad_safety_reason=CgA&thumbnail_url=https://i.ytimg.com/vi/rzkoQFbzmOk/default.jpg&innertube_api_key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8&atc=a=3&b=32vy80AGa-Bgh5X78MGIbmu2Kto&c=1500147363&d=1&e=rzkoQFbzmOk&c3a=26&c1a=1&c6a=1&hh=1HDgx0VAJl0SXzxb45QsrH_lAKVbaJ_K7iaF7J_ogxg&iv_load_policy=1&fade_out_start_milliseconds=0&instream_long=False&avg_rating=4.95149946213&of=hXWnIfY7eipoBieXZpOJwA&ismb=4450000&xhr_apiary_host=youtubei.youtube.com&loeid=9413138,9422596,9431012,9434289,9441394,9444433,9444893,9450707,9451825,9460350,9463578,9465813,9475121,9475579,9476699,9478199,9478523,9479324,9480114,9480538,9481125,9481317,9482504,9482602,9482851,9483147,9483258,9483501&enablecsi=1&account_playback_token=QUFFLUhqbG5Ta1k2bjVZNXE1S1RjeXJma0dYOVhJTlgtUXxBQ3Jtc0trRmxkREVqN1pxcjVPNTB3UUFxOG13RTNoVG1UQ0t4bDFNM3ZyQXhHbGtRQ1FyaWNYSGttZXlVTktEeGc3clQwNkFBNy1Bb08zTEJ6TDZNYkxWN2dwR1JfTWlQbnEyTE9DdDdNNUNGT1pTX3BrZU5aTQ==&fade_in_start_milliseconds=-3000&relative_loudness=0.760999679565&afv_ad_tag=https://googleads.g.doubleclick.net/pagead/ads?ad_type=text_image&channel=Vertical_1021+Vertical_1036+Vertical_1408+Vertical_211+Vertical_36+Vertical_590+Vertical_613+afv_overlay+afv_user_id_IO0szsIo5AKIFmbbhfxFqw+afv_user_lundgrenrob+invideo_overlay_480x70_cat10+yt_cid_679125+yt_mpvid_xxV6hpjhJlzWVUm7+yt_no_360+yt_no_3pas+yt_no_ap+yt_no_cp+yt_no_wa+ytdevice_1+ytdevicever_1.20170712+ytel_embedded+ytps_default&client=ca-pub-6219811747049371&dbp=ChZoWFduSWZZN2VpcG9CaWVYWnBPSndBEAEgASgA&description_url=http://www.youtube.com/video/rzkoQFbzmOk&eid=148648206&hl=en&host=ca-host-pub-7533488853144487&ht_id=5547539&loeid=9413138,9422596,9431012,9434289,9441394,9444433,9444893,9450707,9451825,9460350,9463578,9465813,9475121,9475579,9476699,9478199,9478523,9479324,9480114,9480538,9481125,9481317,9482504,9482602,9482851,9483147,9483258,9483501&osd=2&pucrd=CgYIABAAGAA&sdki=18803DAD&url=http://www.youtube.com/video/rzkoQFbzmOk&v_p=JY0c2kM=&ytdevice=1&ytdevicever=1.20170712&yt_pt=APb3F2_FMmSD8mG8PMmMq7urTSbmCkJ0Bga4WDpKEQV0vAboVlPPijEHbExGYSXuMBmFcOJpCrpa2LhYnrkbgQbnWXXOarZjCKizS68OiIqOlB2GrZui5-ggUQ6aT7w6CaS_ifnYBnZXHpId9iX76vg6ufeyBrm43Pn8XtzfKSqvqvC1W8CRVv5me3zlMAU8-o1WblaDrL0g1b7SL7ot8DDGof6LRYQvNLPRCMZ6cjjIRMd62t7yetC6yMM2gjL_wZnSM_yKWhGZZgCWLQpIGY40tHARFRtOCCQsri5ttw&yt_vis=0&is_listed=1&cafe_experiment_id=148648206&mpvid=xxV6hpjhJlzWVUm7&cver=1.20170712&ptchn=IO0szsIo5AKIFmbbhfxFqw&fade_in_duration_milliseconds=1000&video_id=rzkoQFbzmOk&allow_html5_ads=1&dbp=Ch4KFmhYV25JZlk3ZWlwb0JpZVhacE9Kd0EQASABKAAQARgC&as_launched_in_country=1&iv_invideo_url=https://www.youtube.com/annotations_invideo?cap_hist=1&video_id=rzkoQFbzmOk&client=1&ei=om5qWfj6NYL_WNjYpIAD&csi_page_type=embed&keywords=rob+lundgren,cover,rock,metal,voice,vocal,live+vocal,lundgren,robin+lundgren,robin,nothing+else+matters,metallica,nem,nothing+else+matters+cover,acoustic+cover,n.e.m.,nem+cover,nothing+else+matters+acoustic+cover,metallica+cover,black+album&eventid=om5qWfj6NYL_WNjYpIAD&iv3_module=1&cr=US&root_ve_type=27240&cid=679125&fexp=9413138,9422596,9431012,9434289,9441394,9444433,9444893,9446364,9449243,9450707,9453897,9457141,9458230,9463578,9463594,9465813,9466793,9466795,9466797,9467217,9468797,9468799,9468805,9475121,9475579,9476699,9477080,9478199,9478523,9479324,9480114,9480475,9480538,9481125,9481317,9482504,9482602,9482648,9483147,9483258,9483501&innertube_context_client_version=1.20170712&author=Rob+Lundgren+Live+Vocals&cl=161729798&apiary_host=&allow_embed=1&ppv_remarketing_url=https://www.googleadservices.com/pagead/conversion/971134070/?backend=innertube&cname=1&cver=1_20170712&data=backend=innertube;cname=1;cver=1_20170712;dactive=None;dynx_itemid=rzkoQFbzmOk;ptype=ppv&label=iuZUCLmC72YQ9qiJzwM&ptype=ppv&token=1&swf_player_response=1&idpj=-9&fmt_list=22/1280x720/9/0/115,43/640x360/99/0/0,18/640x360/9/0/115,36/320x180/99/1/0,17/176x144/99/1/0&probe_url=https://r5---sn-q4f7sn76.googlevideo.com/videogoodput?id=o-AEixTmbMug2neWtp5U1Tb-21J9uJ59IBSUY4nJ2T0axm&source=goodput&range=0-4999&expire=1500150962&ip=95.14.68.108&ms=pm&mm=35&pl=24&nh=IgpwZjAyLmRmdzA2Kgs2Ni4xMTAuNTcuNQ&sparams=id,source,range,expire,ip,ms,mm,pl,nh&signature=147AA9BCF3169578802C44A7735BBB7926C37092.5C2597F4730C259D6DDCD8AAAB093C906A61E8AB&key=cms1&itct=CAEQu2kiEwj407O1hIzVAhWCPxYKHVgsCTAo6NQB&shortform=True&t=1&watermark=,https://s.ytimg.com/yts/img/watermark/youtube_watermark-vflHX6b6E.png,https://s.ytimg.com/yts/img/watermark/youtube_hd_watermark-vflAzLcD6.png&host_language=en&excluded_ads=46=14_14;59=14_14;61=1_3,2_3;64=14_14;65=15_2,15_2_1,15_2_4,17_2,17_2_1;84=1_1,1_2,1_2_1,1_3,2_2,2_2_1,2_2_4,2_3,15_2,15_2_1,15_2_4,17_2,17_2_1;89=2_2,15_2;94=15_2,15_2_1,15_2_4,17_2,17_2_1&title=NOTHING+ELSE+MATTERS+(Live+Vocal+&+Acoustic+Cover)&innertube_api_version=v1&allow_ratings=1&pltype=content&ptk=BroadbandTV_Music&csn=om5qWfj6NYL_WNjYpIAD&oid=3q6zKQH3OljiViOJ67PJOw&status=ok&allow_below_the_player_companion=True&loudness=-20.2390003204&ad_slots=0,-1&url_encoded_fmt_stream_map=type=video/mp4;+codecs="avc1.64001F,+mp4a.40.2"&itag=22&quality=hd720&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&lmt=1497979410219532&key=yt6&initcwndbps=556250&ipbits=0&mv=m&source=youtube&expire=1500168963&mn=sn-4g5e6nls&ratebypass=yes&mt=1500147287&pl=21&itag=22&ms=au&requiressl=yes&mime=video/mp4&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.570&mm=31&ip=95.14.68.108&signature=5E6066364965F76E6BC61052DC402531E5F319B2.A3BBC0015021650C424E050CD546133A23578F5B&sparams=dur,ei,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pl,ratebypass,requiressl,source,expire,type=video/webm;+codecs="vp8.0,+vorbis"&itag=43&quality=medium&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&initcwndbps=556250&expire=1500168963&ratebypass=yes&clen=48022685&source=youtube&signature=771D35EFBBDC827F178E06B5B40372EA337A7E9F.6E06C0E37004690B1BF766340415170E296378ED&lmt=1497816143039353&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=43&ms=au&requiressl=yes&mime=video/webm&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=0.000&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pl,ratebypass,requiressl,source,expire,type=video/mp4;+codecs="avc1.42001E,+mp4a.40.2"&itag=18&quality=medium&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&initcwndbps=556250&expire=1500168962&ratebypass=yes&clen=42156239&source=youtube&signature=B20E84210DACE3069FC90109B0B4CCD229468AD2.C02B2E5EF9C162E4E2201DA9062571FC6D511010&lmt=1497979373206161&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=18&ms=au&requiressl=yes&mime=video/mp4&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.570&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pl,ratebypass,requiressl,source,expire,type=video/3gpp;+codecs="mp4v.20.3,+mp4a.40.2"&itag=36&quality=small&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&initcwndbps=556250&expire=1500168963&clen=12684319&source=youtube&signature=384C051D8C33CEFB6E28062E460398765AB5680D.265633CF03B2E0ED7DC72A3C6F3B788D6E10FEF1&lmt=1497814285338647&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=36&ms=au&requiressl=yes&mime=video/3gpp&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.640&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,i...e&html5_subsegment_readahead_target_buffer_health_secs=0.5&report_promotes_terrorism_mobile_web=true&html5_disable_move_pssh_to_moov=true&html5_max_av_sync_drift=50&enable_playlist_multi_season=true&html5_suspend_manifest_on_pause=true&show_countdown_on_bumper=true&html5_always_reload_on_403=true&html5_repredict_interval_secs=0.0&signed_out_notifications_inbox=true&stop_using_ima_sdk_gpt_request_activity=true&kids_mqb_use_confirmed_safe_videos_only=true&html5_new_fallback=true&html5_subsegment_readahead_timeout_secs=2.0&android_native_live_enablement=true&html5_adjust_effective_request_size=true&html5_hopeless_mode_request_size_secs=40&mpu_visible_threshold_count=2&vss_dni_delayping=0&disable_new_pause_state3=true&html5_disable_non_contiguous=true&flex_theater_mode=true&lugash_header_warmup=true&html5_min_readbehind_cap_secs=0&youtubei_for_web=true&disable_reporting_html5_no_vast_ads_as_error=true&html5_vp9_live_whitelist=false&html5_suspended_state=true&html5_connect_timeout_secs=7.0&web_player_flash_fallback_killswitch=true&use_push_for_desktop_live_chat=true&html5_min_secs_between_format_selections=8.0&gapi_hint_params=m;/_/scs/abc-static/_/js/k=gapi.gapi.en.BznCEch7yrY.O/m=__features__/rt=j/d=1/rs=AHpOoo89FbxkNsIBOnpzYJliP4nzTuPXPg&view_count=138746&gut_tag=/4061/ytunknown/main&core_dbp=ChZoWFduSWZZN2VpcG9CaWVYWnBPSndBEAEgASgA&midroll_freqcap=600.0&apply_fade_on_midrolls=True&ad3_module=1&iv_allow_in_place_switch=1&adaptive_fmts=init=0-715&itag=137&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=142261087&source=youtube&signature=A81AFBC28F4D37951D2A3CA9F9370EBC07E410E4.BD5547C59956D93C2B351B302DFD86E85451A0CA&lmt=1497979028342198&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=137&ms=au&requiressl=yes&mime=video/mp4&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.520&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=3799443&type=video/mp4;+codecs="avc1.640028"&lmt=1497979028342198&projection_type=1&quality_label=1080p&index=716-1827&size=1920x1080&clen=142261087,init=0-242&itag=248&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=158398468&source=youtube&signature=CCC0D2490353B0065E5829F151305D95AEDE55B9.7CF4D0EE40ACB221728D8AFDF084E6A5DFABCD98&lmt=1497816474083876&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=248&ms=au&requiressl=yes&mime=video/webm&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.480&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=3123739&type=video/webm;+codecs="vp9"&lmt=1497816474083876&projection_type=1&quality_label=1080p&index=243-1842&size=1920x1080&clen=158398468,init=0-713&itag=136&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=79105869&source=youtube&signature=CDB118EDE7B63DDC9550F367E9F07830799655ED.D3EF922360819B481CF6ECC2763559AB0C3478AF&lmt=1497979016153211&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=136&ms=au&requiressl=yes&mime=video/mp4&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.520&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=2332623&type=video/mp4;+codecs="avc1.4d401f"&lmt=1497979016153211&projection_type=1&quality_label=720p&index=714-1825&size=1280x720&clen=79105869,init=0-242&itag=247&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=86507558&source=youtube&signature=93A41C597A00D1FA8E3D96781BF75C7DE64D9B1B.4DFE8C0F918A97505996A2CC7549D48D260BEBF5&lmt=1497816799001841&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=247&ms=au&requiressl=yes&mime=video/webm&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.480&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=1767900&type=video/webm;+codecs="vp9"&lmt=1497816799001841&projection_type=1&quality_label=720p&index=243-1834&size=1280x720&clen=86507558,init=0-714&itag=135&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=44918449&source=youtube&signature=1B71C220D58B22A6971AADFB121760093B6B2C16.6FFD92B792E9A31D2F69B194D3ED2D0548E7F245&lmt=1497979015179453&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=135&ms=au&requiressl=yes&mime=video/mp4&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.520&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=1168568&type=video/mp4;+codecs="avc1.4d401e"&lmt=1497979015179453&projection_type=1&quality_label=480p&index=715-1826&size=854x480&clen=44918449,init=0-242&itag=244&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=42553772&source=youtube&signature=946B26FD19005B4A77678CF58359B091AA196647.AF6B0B71C672F97F34B50DDFCE58B184A86DD311&lmt=1497816797643690&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=244&ms=au&requiressl=yes&mime=video/webm&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.480&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=891875&type=video/webm;+codecs="vp9"&lmt=1497816797643690&projection_type=1&quality_label=480p&index=243-1816&size=854x480&clen=42553772,init=0-714&itag=134&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=23508086&source=youtube&signature=1C0ECE53DF3F8D44509FB39E4E482A810BCC080E.916A6FF5E8B24D9B7A650A180C4984C15AB78E5B&lmt=1497979014659412&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=134&ms=au&requiressl=yes&mime=video/mp4&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.520&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=633970&type=video/mp4;+codecs="avc1.4d401e"&lmt=1497979014659412&projection_type=1&quality_label=360p&index=715-1826&size=640x360&clen=23508086,init=0-242&itag=243&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=23535825&source=youtube&signature=64D565D1DF5DE6B15DC5EE2EE615B2B69A27FD54.AA0F53B5E818B5653291E9755A2712E501028609&lmt=1497816797800637&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=243&ms=au&requiressl=yes&mime=video/webm&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.480&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=478817&type=video/webm;+codecs="vp9"&lmt=1497816797800637&projection_type=1&quality_label=360p&index=243-1788&size=640x360&clen=23535825,init=0-713&itag=133&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=13962368&source=youtube&signature=6CAFDFFD0FB4A1CCFDA3C54B7473FF2569EFE8AC.AEA43F8A56C9028D31932DBE1F7AF042E40099A7&lmt=1497979014440001&ipbits=0&mv=m&gir=yes&mt=1500147287&pl=21&itag=133&ms=au&requiressl=yes&mime=video/mp4&id=o-AIlu0RkrqMnKv9EvUKiHDF8r6kAlczSgWVujKgm6Rz4V&dur=458.520&mm=31&ip=95.14.68.108&mn=sn-4g5e6nls&sparams=clen,dur,ei,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pl,requiressl,source,expire&bitrate=286948&type=video/mp4;+codecs="avc1.4d4015"&lmt=1497979014440001&projection_type=1&quality_label=240p&index=714-1825&size=426x240&clen=13962368,init=0-241&itag=242&fps=25&xtags=&url=https://r1---sn-4g5e6nls.googlevideo.com/videoplayback?ei=om5qWfj6NYL_WNjYpIAD&key=yt6&keepalive=yes&initcwndbps=556250&expire=1500168963&clen=12769212&source=youtube&signature=A49774FB936FBACCFF7993E6644AB6D35B87F6
You see its not full data I need from get_video_info.Its just a part of it.How can i solve this?
Use HttpClient it is much simpler than HttpWebRequest
using (var client = new HttpClient()) {
var response = await client.GetAsync(url);
string content = await response.Content.ReadAsStringAsync();
}
HttpClient is the best of both worlds (i.e. WebClient and HttpWebRequest)

how to read content from webpage

I want to access a webpage & store the contents of the webpage into a database
this is the code I have tried for reading the contents of the webpage
public static WebClient wClient = new WebClient();
public static TextWriter textWriter;
public static String readFromLink()
{
string url = "http://www.ncedc.org/cgi-bin/catalog-search2.pl";
HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = "POST";
System.Net.WebClient client = new System.Net.WebClient();
byte[] data = client.DownloadData(url);
string html = System.Text.Encoding.UTF8.GetString(data);
return html;
}
public static bool WriteTextFile(String fileName, String t)
{
try
{
textWriter = new StreamWriter(fileName);
}
catch (Exception)
{
return false;
Console.WriteLine("Data Save Unsuccessful: Could Not create File");
}
try
{
textWriter.WriteLine(t);
}
catch (Exception)
{
return false;
Console.WriteLine("Data Save UnSuccessful: Could Not Save Data");
}
textWriter.Close();
return true;
Console.WriteLine("Data Save Successful");
}
static void Main(string[] args)
{
String saveFile = "E:/test.txt";
String reSultString = readFromLink();
WriteTextFile(saveFile, reSultString);
Console.ReadKey();
}
but this code gives me an o/p as- This script should be referenced with a METHOD of POST. REQUEST_METHOD=GET
please tell me how to resolve this
You are mixing HttpWebRequest with System.Net.WebClient code. They are a different. You can use WebClient.UploadValues to send a POST with WebClient. You will also need to provide some POST data:
System.Net.WebClient client = new System.Net.WebClient();
NameValueCollection postData = new NameValueCollection();
postData.Add("format","ncread");
postData.Add("mintime","2002/01/01,00:00:00");
postData.Add("minmag","3.0");
postData.Add("etype","E");
postData.Add("outputloc","web");
postData.Add("searchlimit","100000");
byte[] data = client.UploadValues(url, "POST", postData);
string html = System.Text.Encoding.UTF8.GetString(data);
You can find out what parameters to pass by inspecting the POST message in Fiddler. And yes, as commented by #Chris Pitman, use File.WriteAllText(path, html);
I'm not sure if it's a fault on your side as I get the same message just by opening the page. The page source does not contain any html so I don't think you can do webRequest.Method = "POST". Have you spoken to the administrators of the site?
The .NET framework provides a rich set of methods to access data stored on the web. First you will have to include the right namespaces:
using System.Text;
using System.Net;
using System.IO;
The HttpWebRequest object allows us to create a request to the URL, and the WebResponse allows us to read the response to the request.
We’ll use a StreamReader object to read the response into a string variable.
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sr.Close();
myResponse.Close();
In this code sample, the URL variable should contain the URL that you want to get, and the result variable will contain the contents of the web page. You may want to add some error handling as well for a real application.
As far as I see, the URL you're requesting is a perl script. I think it demands POST to get search arguments and therefore delivers search results.

C# WebRequest won't work with this link from LinkShare

This is driving me a bit nuts. I am trying to do something quite simple, and I have done it many times before. Just trying to call a REST API.
I am trying to call GetMessage with endpoint = "http://feed.linksynergy.com/productsearch?token=717f8c8511725ea26fd5c3651f32ab187d8db9f4b208be781c292585400e682d&keyword=DVD", and it keeps returning empty string. If I pass it any other valid URL, it will work. But if I just copy and paste the original URL into the web browser, it returns fine!
Can any smart developer tell me what's going on?
Code below. Thanks in advance.
James
public string GetMessage(string endPoint)
{
HttpWebRequest request = CreateWebRequest(endPoint);
using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;
if (response.StatusCode != HttpStatusCode.OK)
{
string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}
// grab the response
using (var responseStream = response.GetResponseStream())
{
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}
return responseValue;
}
}
private HttpWebRequest CreateWebRequest(string endPoint)
{
var request = (HttpWebRequest)WebRequest.Create(endPoint);
request.Method = "GET";
request.ContentLength = 0;
request.ContentType = "text/xml";
return request;
}
Not sure why your setting ContentLength/ContentType - that is generally for HTTP POST, where there is a request body for which you write data to via a stream.
This is a HTTP GET, so there is no request body. (just URI w/ query string)
This should work:
using System;
using System.IO;
using System.Net;
using System.Text;
// Create the web request
HttpWebRequest request = WebRequest.Create("http://www.someapi.com/") as HttpWebRequest;
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output
Console.WriteLine(reader.ReadToEnd());
}
EDIT
#Gabe is also quite right - try this on another computer, that is isn't behind any kind of firewall/proxy server.
My work PC was behind a proxy server, so in order to make REST-based HTTP calls, i needed to do this:
var proxyObject = new System.Net.WebProxy("http://myDomain:8080/", true);
System.Net.WebRequest req = System.Net.WebRequest.Create("http://www.someapi.com/");
req.Proxy = proxyObject;
proxyObject.Credentials = New System.Net.NetworkCredential("domain\username","password")

Reading remote file [C#]

I am trying to read a remote file using HttpWebRequest in a C# Console Application. But for some reason the request is empty - it never finds the URL.
This is my code:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://uo.neverlandsreborn.org:8000/botticus/status.ecl");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
How come this is not possible?
The file only contains a string. Nothing more!
How are you reading the response data? Does it come back as successful but empty, or is there an error status?
If that doesn't help, try Wireshark, which will let you see what's happening at the network level.
Also, consider using WebClient instead of WebRequest - it does make it incredibly easy when you don't need to do anything sophisticated:
string url = "http://uo.neverlandsreborn.org:8000/botticus/status.ecl";
WebClient wc = new WebClient();
string data = wc.DownloadString(url);
You have to get the response stream and read the data out of that. Here's a function I wrote for one project that does just that:
private static string GetUrl(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode != HttpStatusCode.OK)
throw new ServerException("Server returned an error code (" + ((int)response.StatusCode).ToString() +
") while trying to retrieve a new key: " + response.StatusDescription);
using (var sr = new StreamReader(response.GetResponseStream()))
{
return sr.ReadToEnd();
}
}
}

WebRequest to connect to the Wikipedia API

This may be a pathetically simple problem, but I cannot seem to format the post webrequest/response to get data from the Wikipedia API. I have posted my code below if anyone can help me see my problem.
string pgTitle = txtPageTitle.Text;
Uri address = new Uri("http://en.wikipedia.org/w/api.php");
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string action = "query";
string query = pgTitle;
StringBuilder data = new StringBuilder();
data.Append("action=" + HttpUtility.UrlEncode(action));
data.Append("&query=" + HttpUtility.UrlEncode(query));
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
request.ContentLength = byteData.Length;
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream.
StreamReader reader = new StreamReader(response.GetResponseStream());
divWikiData.InnerText = reader.ReadToEnd();
}
You might want to try a GET request first because it's a little simpler (you will only need to POST for wikipedia login). For example, try to simulate this request:
http://en.wikipedia.org/w/api.php?action=query&prop=images&titles=Main%20Page
Here's the code:
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://en.wikipedia.org/w/api.php?action=query&prop=images&titles=Main%20Page");
using (HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse())
{
string ResponseText;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
ResponseText = reader.ReadToEnd();
}
}
Edit: The other problem he was experiencing on the POST request was, The exception is : The remote server returned an error: (417) Expectation failed. It can be solved by setting:
System.Net.ServicePointManager.Expect100Continue = false;
(This is from: HTTP POST Returns Error: 417 "Expectation Failed.")
I'm currently in the final stages of implementing an C# MediaWiki API which allows the easy scripting of most MediaWiki viewing and editing actions.
The main API is here: http://o2platform.googlecode.com/svn/trunk/O2%20-%20All%20Active%20Projects/O2_XRules_Database/_Rules/APIs/OwaspAPI.cs and here is an example of the API in use:
var wiki = new O2MediaWikiAPI("http://www.o2platform.com/api.php");
wiki.login(userName, password);
var page = "Test"; // "Main_Page";
wiki.editPage(page,"Test content2");
var rawWikiText = wiki.raw(page);
var htmlText = wiki.html(page);
return rawWikiText.line().line() + htmlText;
You seem to be pushing the input data on HTTP POST, but it seems you should use HTTP GET.
From the MediaWiki API docs:
The API takes its input through
parameters in the query string. Every
module (and every action=query
submodule) has its own set of
parameters, which is listed in the
documentation and in action=help, and
can be retrieved through
action=paraminfo.
http://www.mediawiki.org/wiki/API:Data_formats

Categories