小编You*_*dir的帖子

Xamarin Android httpwebrequest,无法访问已处置的对象

我有一个Android移动应用程序,我想发送webrequest到服务器发布一些数据,但在发布数据之前,我发送一个http获取请求获取一些数据,然后发送邮件请求,首先我收到成功,但当我发送邮件请求它会抛出我的代码的这行代价 requestStream.Write(bytes, 0, bytes.Length);

例外是:

System.ObjectDisposedException:无法访问已处置的对象.对象名:'System.Net.Sockets.NetworkStream'.

这是我的获取和发布请求代码GET:

public void GetTokenInfo()
        {

            try
            {
                var uri = new Uri(string.Format(_host + "webserver/SesTokInfo", string.Empty));
                var webRequest = WebRequest.Create(uri);
                using (var response = webRequest.GetResponse() as HttpWebResponse)
                {
                    using (var requestStream = response.GetResponseStream())
                    {
                        using (var reader = new StreamReader(requestStream))
                        {
                            var content = reader.ReadToEnd();
                            XmlDocument xDocument = new XmlDocument();
                            xDocument.LoadXml(content);
                            XmlElement root = xDocument.DocumentElement;
                            if (IsResponseReturned(root))
                            {
                                GlobalConfig.SessionId = root.GetElementsByTagName("SesInfo")[0].InnerText;
                                GlobalConfig.Token = root.GetElementsByTagName("TokInfo")[0].InnerText;

                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            } …
Run Code Online (Sandbox Code Playgroud)

c# post android webrequest xamarin

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

使用rest客户端应用程序发送Web请求,但不使用c#

我正在通过c#webrequest和httpClient向api发送一个帖子请求但是我总是从api收到一条错误消息,说明你在标题中发布了无效数据,但重点是我用chrome扩展高级休息客户端发送相同的数据工作得很好,我比较了两个请求没有什么不同,我已经附加了请求和我的代码,任何人都可以帮助找出问题所在,

这是来自其他客户端应用程序的请求:

在此输入图像描述

这是来自c#的请求

在此输入图像描述

这是我的c#代码

 string item = "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>" +
  "<request>" +
  "<Username>admin</Username>" +
  "<Password>" + password + "</Password>" +
  "<password_type>4</password_type>" +
  "</request> ";
var request = (HttpWebRequest)WebRequest.Create("http://192.168.8.1/api/user/login");
request.Method = "POST";
request.Headers["_RequestVerificationToken"]= Token;
request.Headers["Cookie"] = Sess;
byte[] bytes = Encoding.UTF8.GetBytes(item);
request.ContentType = "application/xml;charset=UTF-8";
request.ContentLength = bytes.Length;
Stream streamreq = request.GetRequestStream();
streamreq.Write(bytes, 0, bytes.Length);
streamreq.Close();
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
    var result = reader.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)

c# api post webrequest

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

ActionLink路由包含特定字符的值

我正在使用此动作链接向路由器发送路由值id,但我的id值是这样的config.xml ,这里是我的动作链接

 @Html.ActionLink("Destroy", "DeleteFile", "Files", new { id = "config.xml"})
Run Code Online (Sandbox Code Playgroud)

问题是,当我想点击此链接时,浏览器会将其理解为url最终结果config.xml

像这样

http://localhost:12380/Files/DeleteFile/config.xml
Run Code Online (Sandbox Code Playgroud)

并且不会转到它返回的控制器404 - not found.如何防止这种情况发生,并将其config.xml作为参数而不是文件?

这也是我的路线

routes.MapRoute(
              name: "delete files",
              url: "Files/DeleteFile/{id}",
              defaults: new
              {
                  controller = "Files",
                  action = "DeleteFile",
                  id= UrlParameter.Optional
              }
            );
Run Code Online (Sandbox Code Playgroud)

我也试过id ,filename但没有改变

这是我的控制器

[HttpGet]
        public ActionResult DeleteFile(string id)
        {
          return view("DeleteFile");
         }
Run Code Online (Sandbox Code Playgroud)

c# actionlink routevalues razor

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

将linq查询创建为字符串

我有一个包含linq查询的字符串,我有一个动态where子句也作为包含许多动态条件的字符串这里是我的where子句

string strWhereString = "where a.id==1 && a.name==\"something\"";
Run Code Online (Sandbox Code Playgroud)

这是我的linq查询字符串:

var query = "from a in context.tblName "+strWhereString;
Run Code Online (Sandbox Code Playgroud)

问题是如何运行此查询并从表中获取结果?有没有办法做到这一点或Linq不支持这个?

c# linq string

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

备份SQL Server数据库并将其邮寄

我已经搜索寻找一种备份sql server db并将备份文件发送到带有sql server mail配置文件的电子邮件地址的方法,但我没有得到它,我发现有关在db发生故障时发送电子邮件以及其他通知但是我没有看到有关备份并将其自动发送到电子邮件的信息,有什么办法可以创建工作来做到这一点?谢谢。

sql-server email profile backup jobs

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

合并字符串c​​#中的所有json路径

我有一个很大的 json 数据,我想从根获取所有路径,直到获取路径的值,然后将结果存储到字符串中,如下所示,这里是我的 json

{  
   "root":{  
      "first":{  
         "first1":{  
            "value":"1"
         },
         "first2":{  
            "value":"2"
         },
         "first3":{  
            "value":"3"
         }
      },
      "second":{  
         "second1":{  
            "value":"1"
         },
         "second2":{  
            "value":"2"
         },
         "second3":{  
            "value":"3"
         }
      },
      "third":{  
         "third1":{  
            "value":"1"
         },
         "third2":{  
            "value":"2"
         },
         "third3":{  
            "value":"3"
         }
      },
      "four":{  
         "value":"4"
      },
      "five":{  
         "five1":{  
            "five11":{  
               "value":"five11"
            },
            "five12":{  
               "value":"five12"
            }
         },
         "five2":{  
            "five21":{  
               "five211":{  
                  "value":"five211"
               }
            }
         }
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

然后我想在 C# 中动态地创建每个路径,并在屏幕中显示,请告诉我一种方法

root.first.first1.value
root.first.first2.value
root.first.first3.value

root.second.second1.value
......

root.four.value

root.five.five1.five11.value
root.five.five1.five12.value
....
root.five2.five21.five211.value 
Run Code Online (Sandbox Code Playgroud)

c# string json path

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

标签 统计

c# ×5

post ×2

string ×2

webrequest ×2

actionlink ×1

android ×1

api ×1

backup ×1

email ×1

jobs ×1

json ×1

linq ×1

path ×1

profile ×1

razor ×1

routevalues ×1

sql-server ×1

xamarin ×1