且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 URL 参数发送到 xamarin API 中的 api

更新时间:2023-01-01 17:35:57

You should search properly before you ask the question

this solution is not just limited for Xamarin

if this is your api link: "http://yourapi/chat?msg=yourmsg"

and incoming msg is say "Your Msg"

and you are getting "http://yourapi/chat?msg=your msg"

this surely is not going to work

your desired string must be: "http://yourapi/chat?msg=your%20msg" (If your api recognizes this well)

then this is the solution for you

// you Need to add a Reference to the System.Web assembly.
using System.Web;
var etMsg= FindViewById<EditText> (Resource.Id.editText);
string msg =etMsg.Text.ToString ();
string url = "http://yourapi/chat?msg=" + HttpUtility.UrlEncode(msg);

Any Special Characters can be url encoded with this solution

Happy Coding