将.Net代码编译为Javascript [英] compiling the .Net code to the Javascript

查看:69
本文介绍了将.Net代码编译为Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们!..


我最近将我的手机与SureMDM集成,这是一个EMM软件。


API in他们的文档(http://mars.42gears.com/support/inout/mdm/api.html)使用.NET编写代码,而iam不熟悉.NET。 所以我不能继续我的开发。


他们的文档中的代码:

 使用 var  client = new  HttpClient ())
{
client.BaseAddress = new Uri (" HTTPS://suremdm.42gears.com/api");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue (" Basic",
转换 .ToBase64String(编码 .ASCII.GetBytes( String .Format(" {0}:{1}",username,password))));
client.DefaultRequestHeaders.TryAddWithoutValidation(" ApiKey",ApiKey);
//你的代码在这里
}

我在Postman ide中试过的代码


方法:获取


网址:  http://suremdm.42gears.com/api/location?DeviceID=rpr@gmail.com


DeviceId在params部分添加。


Headers:Content-type: application / json ApiKey:
Basic ***************


Iam geting
"用户名密码不匹配"错误回复 状态为401未经授权


所以有人可以说我在这里缺少什么吗?       我甚至尝试使用一些在线编译器编译,但我没有得到尊重的结果。  


提前致谢..




 

解决方案


代码会将用户名和密码转换为Base64String,因此您可以尝试使用btoa()来转换JavaScript中的字符串。


以下是一些供您参考的链接。


https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding


HTTPS://小号tackoverflow.com/questions/2820249/base64-encoding-and-decoding-in-client-side-javascript


最好的问候,



hey guys!..

I am recently integrated my mobile with SureMDM which is an EMM software.

The API in their docs (http://mars.42gears.com/support/inout/mdm/api.html) having the code in .NET and iam not familiar with .NET.  so i cant proceed with my development.

code in their doc:

using (var client = new HttpClient())
{
	client.BaseAddress = new Uri("https://suremdm.42gears.com/api");
	client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", 
	Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("{0}:{1}", username, password))));
	client.DefaultRequestHeaders.TryAddWithoutValidation("ApiKey", ApiKey);
	// your code goes here
}

my code which i tried in Postman ide

method : Get

URL : http://suremdm.42gears.com/api/location?DeviceID=rpr@gmail.com

DeviceId is added in params section.

Headers : Content-type :application/json ApiKey: Basic ***************

Iam geting "Username password does not match" error response with  status as 401 unauthorized

So can anyone say what iam missing here?       I even tried to compile with some online compiler but i dont get the respected result.  

Thanks in advance..

 

解决方案

Hi,

The code will convert user name and password to Base64String so you could try to use btoa() to convert the string in JavaScript.

Here are some links for your reference.

https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding

https://stackoverflow.com/questions/2820249/base64-encoding-and-decoding-in-client-side-javascript

Best Regards,

Lee


这篇关于将.Net代码编译为Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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