小编Ale*_*der的帖子

在UWP应用程序中模拟输入

是否可以在UWP应用程序中以编程方式模拟键盘和鼠标输入?

如果是 - 怎么样?

我找到了仅适用于Windows窗体的解决方案.

c# uwp

4
推荐指数
1
解决办法
1425
查看次数

Web API 未收到序列化对象的 json

客户端代码:

        public async Task<ActionResult> Login(UserLoginModel user)
    {
        UserModel data = new UserModel
        {
            Username = user.Username,
            Password = user.Password.GenerateHash()
        };

        var serializedData = JsonConvert.SerializeObject(data);

        var url = "http://localhost:55042/api/Login";

        var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Method = "POST";
        httpWebRequest.Accept = "application/json";

        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            streamWriter.Write(serializedData);
            streamWriter.Flush();
            streamWriter.Close();
        }

        bool deserializedResult = false;
        using (var response = httpWebRequest.GetResponse() as HttpWebResponse)
        {
            if (httpWebRequest.HaveResponse && response != null) {
                using (var streamReader = new StreamReader(response.GetResponseStream())) {
                    var result …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc asp.net-web-api asp.net-web-api2

2
推荐指数
1
解决办法
1484
查看次数

HttpClient {StatusCode: 415, ReasonPhrase: '不支持的媒体类型'

我尝试在方法中调用我的 API,但出现错误:{StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'。我一直在环顾四周,发现很多人都遇到了同样的问题,但是通过在创建 StringContent 时添加媒体类型已经解决了。我已经设置了字符串内容,但仍然出现错误。

这是我尝试调用 API 的方法:

    [HttpGet]
    public async Task<ActionResult> TimeBooked(DateTime date, int startTime, int endTime, int id)
    {

        var bookingTable = new BookingTableEntity
        {
            BookingSystemId = id,
            Date = date,
            StartTime = startTime,
            EndTime = endTime
        };

        await Task.Run(() => AddBooking(bookingTable));

        var url = "http://localhost:60295/api/getsuggestions/";

        using (var client = new HttpClient())
        {
            var content = new StringContent(JsonConvert.SerializeObject(bookingTable), Encoding.UTF8, "application/json");
            var response = await client.GetAsync(string.Format(url, content));
            string result = await response.Content.ReadAsStringAsync();

            var timeBookedModel = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-web-api

2
推荐指数
1
解决办法
5919
查看次数

如何在 .net core 的返回 xml 中删除 xmlns:xsi 和 xmlns:xsd?

这是我的代码:

[HttpPost]
[Produces("application/xml")]
public async Task<xml> mp([FromBody]xml XmlData)
{
    xml ReturnXmlData = null;
    ReturnXmlData = new xml()
    {
        ToUserName = XmlData.FromUserName,
        FromUserName = XmlData.ToUserName,
        CreateTime = XmlData.CreateTime,
        MsgType = "text",
        Content = "Hello world"
    };
    return ReturnXmlData;
}
[XmlRoot("xml")]
public class xml
{
    public string ToUserName { get; set; }
    public string FromUserName { get; set; }
    public string CreateTime { get; set; }
    public string MsgType { get; set; }
    public string MsgId { get; set; }
    public string …
Run Code Online (Sandbox Code Playgroud)

c# .net-core asp.net-core

2
推荐指数
1
解决办法
1757
查看次数

Web API端点不适用于邮递员,但可以大张旗鼓

我正在使用WebAPI .Net Core 2.2,我已经成功添加了swagger,并且可以从swagger UI创建POST或GET请求。但是当我从Postman执行端点时,什么也没发生。端点上的中断点均被击中,但邮递员用户界面上未显示正确的结果

[HttpPost]
[Route("Details/{year:int}/Directors")]
public ActionResult DirectoryMoviesByYear(int year) 
{
     //sample code 
     return Ok(new Director { Id=1, Name="Peter Jackson" });

}
Run Code Online (Sandbox Code Playgroud)

邮递员使用的终点 https:// localhost:44386 / api / Movie / Details / 1980 / Directors

这是招摇的屏幕截图,这是招摇的 结果, 这是邮递员的屏幕截图, 在此输入图像描述

.net-core asp.net-core asp.net-core-webapi

1
推荐指数
1
解决办法
634
查看次数

使用 RestSharp 创建特定请求类型

我们正在使用 RestSharp 上传 base64 编码的文件。该 API 需要如下所示的请求格式,但我们无法使用 RestSharp 生成此格式。我想一定有办法吧?

格式1

POST https://www.myapiurl.com/api/v1/add HTTP/1.1
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------330780699366863579549053
Content-Length: 522

----------------------------330780699366863579549053
Content-Disposition: form-data; name="id"

7926456167
----------------------------330780699366863579549053
Content-Disposition: form-data; name="filename"

test2.txt
----------------------------330780699366863579549053
Content-Disposition: form-data; name="description"


----------------------------330780699366863579549053
Content-Disposition: form-data; name="attachment"

dGhpcyBpcyBhIHRlc3Q=
----------------------------330780699366863579549053--
Run Code Online (Sandbox Code Playgroud)

使用 RestSharp,我们只能创建一个如下所示的请求:

格式2

POST https://www.myapiurl.com/api/v1/add HTTP/1.1
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------330780699366863579549053
Content-Length: 83

id=7926456167&filename=SQLSearch.exe&description=&attachment=dGhpcyBpcyBhIHRlc3Q=
Run Code Online (Sandbox Code Playgroud)

对于我们正在使用的 API,除非“附件”参数是一个较大的文件,否则这可以正常工作。如果我们使用 FORMAT 1,我们可以手动撰写/提交对更大文件的请求。FORMAT 2 失败,但这就是我们可以从 RestSharp 中得到的一切。

这是我们正在使用的代码。

var client = new RestClient("http://myapiurl.com/api/v1/add");
var restRequest = new RestRequest(request, Method.POST);
restRequest.AddHeader("Content-Type", "multipart/form-data; boundary=--------------------------330780699366863579549053");
restRequest.AddParameter("id", "7926456167", "multipart/form-data", …
Run Code Online (Sandbox Code Playgroud)

c# api restsharp asp.net-core

0
推荐指数
1
解决办法
1564
查看次数