将 URL 参数发送到 xamarin API 中的 api [英] Send URL parameters to api in xamarin API

查看:31
本文介绍了将 URL 参数发送到 xamarin API 中的 api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在大学项目中的一个聊天应用程序中使用了 xamarin其中我使用 URL 参数向 API 发送聊天消息我的问题是当消息中有空格时,URL 中断并且应用程序崩溃.我想要一个解决方案,在其中我可以将这些空格转换为 %20 标准,以便 API 识别出它是一个空格.

解决方案

提问前应该先搜索一下

<块引用>

此解决方案不仅限于 Xamarin

如果这是您的 api 链接:http://yourapi/chat?msg=yourmsg"

传入的消息是你的消息"

并且您收到http://yourapi/chat?msg=your msg"

这肯定行不通

您想要的字符串必须是:"http://yourapi/chat?msg=your%20msg"(如果你的 api 很好地识别了这一点)

那么这就是你的解决方案

//您需要添加对 System.Web 程序集的引用.使用 System.Web;var etMsg= FindViewById(Resource.Id.editText);string msg =etMsg.Text.ToString();string url = "http://yourapi/chat?msg=" + HttpUtility.UrlEncode(msg);

任何特殊字符都可以使用此解决方案进行 url 编码

快乐编码

I am using xamarin for one of my chat application in college project in which I use URL parameters to send chat messages to API my problem is when there is a space in the message the URL breaks and application crashes. I want the solution in which I can convert those spaces to %20 standards so that API recognizes that it is a space.

解决方案

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

这篇关于将 URL 参数发送到 xamarin API 中的 api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆