我一直在试图弄清楚如何读取httpclient调用的内容,我似乎无法得到它.我得到的响应状态是200,但我无法弄清楚如何获得返回的实际Json,这就是我所需要的!
以下是我的代码:
async Task<string> GetResponseString(string text)
{
var httpClient = new HttpClient();
var parameters = new Dictionary<string, string>();
parameters["text"] = text;
Task<HttpResponseMessage> response =
httpClient.PostAsync(BaseUri, new FormUrlEncodedContent(parameters));
return await response.Result.Content.ReadAsStringAsync();
}
Run Code Online (Sandbox Code Playgroud)
而我只是从一个方法调用它:
Task<string> result = GetResponseString(text);
Run Code Online (Sandbox Code Playgroud)
这就是我得到的
response Id = 89, Status = RanToCompletion, Method = "{null}", Result = "StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:\r\n{\r\n Connection: keep-alive\r\n Date: Mon, 27 Oct 2014 21:56:43 GMT\r\n ETag: \"5a266b16b9dccea99d3e76bf8c1253e0\"\r\n Server: nginx/0.7.65\r\n Content-Length: 125\r\n Content-Type: application/json\r\n}" System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
更新:这是我目前的代码,根据Nathan的回复
async Task<string> …Run Code Online (Sandbox Code Playgroud) 我试图尽可能地限制我$scope在控制器中的使用,并用Controller as语法替换它.
我目前的问题是,我不知道如何$scope.$apply()不使用我的控制器$scope.
编辑:我正在使用TypeScript 1.4和angular
我有这个功能
setWordLists() {
this.fetchInProgress = true;
var campaignId = this.campaignFactory.currentId();
var videoId = this.videoFactory.currentId();
if (!campaignId || !videoId) {
return;
}
this.wordsToTrackFactory.doGetWordsToTrackModel(campaignId, videoId)
.then((response) => {
this.fetchInProgress = false;
this.wordList = (response) ? response.data.WordList : [];
this.notUsedWordList = (response) ? response.data.NotUsedWords : [];
});
}
Run Code Online (Sandbox Code Playgroud)
被叫来
$scope.$on("video-switch",() => {
this.setWordLists();
});
Run Code Online (Sandbox Code Playgroud)
它的(数组wordList和notUsedWordList)在我的视图中没有更新:
<div class="wordListWellWrapper row" ng-repeat="words in wordTrack.wordList">
<div class="col-md-5 wordListWell form-control" ng-class="(words.IsPositive)? …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试按照本教程在 Azure 上的 Ubuntu16.04 虚拟机上部署 DotNetCore 应用程序:https ://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction
将生成的文件夹的内容部署dotnet publish到 vm .... 如果我手动进入项目文件夹并通过 启动 Kestrel dotnet app_name.dll,它可以完美运行,我可以从浏览器访问应用程序。
dotnet app_name.dll手动运行后我从终端得到的输出是
Hosting environment: Production
Content root path: /home/myUser/publish
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
现在,教程要我使用 SystemD 来管理 Kestrel 进程。
它dotnet通过
ExecStart=/usr/bin/dotnet /var/aspnetcore/app_name.dll. 在服务文件中
当我启动该服务时,它看起来会起作用。我得到:
Hosting environment: Production
Content root path: /
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
...但是当我尝试访问该应用程序时,红隼永远不会收到请求。我在两者之间看到的唯一区别是Content root path.
现在,在项目中,startup.cs 中引用了路径: …
我有一个功能,没有使用此功能正确拾取复选框(如果选中):
function playerJson() {
players = [];
$('input[name=playerCheckList]').each(function () {
if ($(this).checked) {
players.push($(this).val());
}
});
return $.toJSON(players);
}
Run Code Online (Sandbox Code Playgroud)
我用这个功能检查所有按钮(正确)
$(function () {
$("#checkAllPlayers").click(function () {
$('input[name=playerCheckList]').each(function () {
$(this).prop('checked', true);
});
});
});
Run Code Online (Sandbox Code Playgroud)
如果我没有if语句:
if($(this).checked)
从第一段代码中,它正确地获取所有值(已检查或未检查)
所以,这个陈述可能是问题所在,但我不确定为什么.
谢谢