之前寫過一篇文章,關於在Android上面取得資料 透過GET方式傳資料給Server(含解決中文編碼問題)

我們來回顧一下 Android 端的Code:

有沒有超多,如果是在Xaramin下面,真的,把上面不好的回憶給忘了吧,我們來看看在Xamarin下有多溫馨

首先看一下畫面 Resources > Layout > Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/btnGetData1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="取得當麻Facebook資料" />
</LinearLayout>
 

btnGetData1按鈕按下後,我會讓他去取得 https://graph.facebook.com/donma.hsu 我在Facebook open graph 中的資料.

直接來看Code :

using Android.App;
using Android.Widget;
using Android.OS;
 
namespace SampleForWebClient
{
    [Activity(Label = "測試取得網路資料", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
 
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
 
            var btnGetData1 = FindViewById<Button>(Resource.Id.btnGetData1);
 
            btnGetData1.Click += btnGetData1_Click;
        }
 
        void btnGetData1_Click(object sender, System.EventArgs e)
        {
            var webClient = new System.Net.WebClient();
            //var result = webClient.DownloadString("http://graph.facebook.com/donma.hsu");
            var result = webClient.DownloadString("https://graph.facebook.com/donma.hsu");
            Toast.MakeText(this, result, ToastLength.Long).Show();
        }
 
      
    }
}
 
結果:
 
有沒有覺得異常的溫馨+孰悉..
沒錯,就是WebClient 在Xamarin 官方網站
直接提到,而且連結就是直接連到MSDN進行參考
 

[Xamarin] 透過WebClient跟網路取得資料 (转帖)的更多相关文章

  1. [Xamarin] 透過 intent-filter 來接管 http ,製作偽瀏覽器 (转帖)

    使用Android 的朋友一定對這畫面不陌生在開啟網址的時候,或是Youtube連結的時候,因為Android 發現,你手機安裝的App有哪些可以支援這些東西的瀏覽 所以,就可以使用甚麼東西來進行開啟 ...

  2. [Xamarin] 透過Native Code呼叫 JavaScript function (转帖)

    今天我們來聊聊關於如何使用WebView 中的Javascript 來呼叫 Native Code 的部分 首先,你得先來看看這篇[Xamarin] 使用Webview 來做APP因為這篇文章至少講解 ...

  3. [Xamarin] 透過StartActivityForResult傳值回來(转贴)

    上一篇文章(開啟另外一個Activity 並且帶資料),提到了開啟一個新的Activity ,我們將值透過intent 帶到下個Activity 但是,如果我們開啟的Actrivity其實是有一個任務 ...

  4. [Xamarin] 透過 IsolatedStorageFile儲存資料(转帖)

    開發手機App通常都會遇到想要儲存資料的,舉個例來說,像是 (圖片來源:http://docs.xamarin.com/guides/android/application_fundamentals/ ...

  5. [Xamarin] 開啟另外一個Activity 並且帶資料 (转帖)

    每隻App是透過許多畫面所組成的,當然可能主畫面之外,都會有許多其他的頁面 再Android 設計中畫面會有配合的Activity 當然在這之前,最好事先了解一下,Android 關於生命週期的規劃 ...

  6. 第五章、 Linux 常用網路指令

    http://linux.vbird.org/linux_server/0140networkcommand.php     第五章. Linux 常用網路指令 切換解析度為 800x600 最近更新 ...

  7. 使用 WebClient 來存取 GET,POST,PUT,DELETE,PATCH 網路資源

    WebClient 基本資訊 提供通用方法使用 WebRequest 類別傳送及接收 URI (支援 http:, https:, ftp:,和 file: ) 的資源 Namespace:Syste ...

  8. [Xamarin.Android] 如何透過電子郵件部署Xamarin.Android App (转帖)

    Android App在部署到實機的時候不像iOS的App限制你一定要使用向Apple申請的開發者憑證,在Apple不管是你要上架到Apple Store或者是企業內部署,你都必須向蘋果申請憑證. 而 ...

  9. [Xamarin] 製作Options Menu、Intent 呼叫網址和Market (转帖)

    Android的設計如果沒意外的話通常有三棵按鈕,BACK,HOME,OPTION (圖片來源:http://developer.android.com/design/index.html) 在OPT ...

随机推荐

  1. Java系列笔记(1) - Java 类加载与初始化

    目录 类加载器 动态加载 链接 初始化 示例 类加载器 在了解Java的机制之前,需要先了解类在JVM(Java虚拟机)中是如何加载的,这对后面理解java其它机制将有重要作用. 每个类编译后产生一个 ...

  2. mongodb下载、安装、配置服务启动、及可视化工具下载、使用

    MongoDB: 1.下载地址:http://www.mongodb.org/downloads(32位还是64位自行选择).我下载的是:mongodb-win32-x86_64-3.2.4-sign ...

  3. php函数的引用返回

    <?php function &test(){ static $b = 1; $b += 2; return $b; } $a = &test(); $a =8; $c = te ...

  4. Shared pool

    Shared pool 一.Shared pool的引入 当你发出一条sql语句交付Oracle,在执行和获取结果前,Oracle对此sql将进行几个步骤的处理过程: 1.语法检查(syntax ch ...

  5. jQuery下拉框插件8种效果

    jQuery自定义漂亮的下拉框插件8种效果 jquery美化选择器实例有:边框.下划线. 伸缩 .滑动. 覆盖. 旋转. 弹出层选择 .环形效果. 在线预览 <body class=" ...

  6. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

  7. MongoDB文档、集合、数据库简介

    文档 概述 文档是MongoDB的核心概念,是数据的基本单元,非常类似于关系数据库中的行.在MongoDB中,文档表示为键值对的一个有序集.MongoDB使用Javascript shell,文档的表 ...

  8. 循环不变量loop invariant 与 算法的正确性

    在论述插入排序的正确性的时候, 书中引入了循环不变量的概念, 刚开始稍微有点不太明白, 早上查了一波资料之后决定把自己的理解记录下来. 什么是循环不变量 ? 在我看来, 所谓循环不变量的就是一个在循环 ...

  9. TableView刷新指定的cell 或section

    //一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:]; [tableview reloadSections:ind ...

  10. iOS AFNetworking “Request failed: unacceptable content-type: text/html”问题

    使用AFNetworking出现报错: error=Error Domain=com.alamofire.error.serialization.response Code=-1016 "R ...