[英]C# Unable to Post JSON Data to Web Server
Im trying to update a webservice. 我正在尝试更新Web服务。 When retrieving the data, the data is received as JSON and this is fine.
检索数据时,将数据作为JSON接收,这很好。 However I'm unable to update the web server.
但是,我无法更新Web服务器。 Below is the response I get when I pull data successfully.
以下是成功提取数据时得到的响应。
{personaId: 1744648419, userName: "Test User 1", userAbbr: "TSTU1", Male: 1, Female: 0, vcredits: 18572,…}
accountCreatedPlatformName: "PC"
actives: [{id: 249147533520, timestamp: 1454819773, LocationID: "ID42331", active: true, assetId: 62,…},…]
bidTokens: {}
userAbbr: "TSTU1"
userName: "Test User 1"
vcredits: 18572
currencies: [{name: "VMONEY", funds: 18572, finalFunds: 18572}, {name: "USER_AWARDS", funds: 0, finalFunds: 0},…]
0: {name: "VMONEY", funds: 18572, finalFunds: 18572}
finalFunds: 18572
funds: 18572
name: "VMONEY"
1: {name: "USER_AWARDS", funds: 0, finalFunds: 0}
finalFunds: 0
funds: 0
name: "USER_AWARDS"
2: {name: "USER_TOKEN", funds: 0, finalFunds: 0}
finalFunds: 0
funds: 0
name: "USER_TOKEN"
divisionBusiness: 3
divisionInterstate: 4
Male: 1
established: "1454819773"
feature: {specials: 0}
Female: 0
personaId: 1744648419
personaName: "TestUser1"
purchased: false
reliability: {reliability: 125, daysActive: 44, daysInactive: 42, daysUnfinishedTime: 0}
seasonTicket: false
accountList: {account: [,…], activeAccId: 3}
cards: 6
unassignedItemSize: 0
unopenedAccounts: {preOrderAcc: 0, recoveredAcc: 0}
pointsWon: 32
I only want to update the following section either one of them or all of them depending on the information provided. 我只想根据提供的信息更新以下部分之一或全部更新。
vcredits: 18572
currencies: [{name: "VMONEY", funds: 18572, finalFunds: 18572}, {name: "USER_AWARDS", funds: 0, finalFunds: 0},…]
0: {name: "VMONEY", funds: 18572, finalFunds: 18572}
finalFunds: 18572
funds: 18572
name: "VMONEY"
1: {name: "USER_AWARDS", funds: 0, finalFunds: 0}
finalFunds: 0
funds: 0
name: "USER_AWARDS"
2: {name: "USER_TOKEN", funds: 0, finalFunds: 0}
finalFunds: 0
funds: 0
name: "USER_TOKEN"
Below is the code I'm using to update 以下是我用来更新的代码
private CreditsResponse vcredits; 私人CreditsResponse vcredits;
public async Task<CreditsResponse> PerformRequestAsync()
{
vcredits = new CreditsResponse();
List<Currency> vmoney = new List<Currency>();
Currency userCoins = new Currency();
userCoins.Name = "VMONEY";
userCoins.FinalFunds = 20000;
userCoins.Funds = 20000;
vmoney.Add(userCoins);
vcredits.Currencies = vmoney;
vcredits.Credits = 20000;
var vMoneyContent = JsonConvert.SerializeObject(vcredits);
HttpContent content = new StringContent(vMoneyContent, Encoding.UTF8, "application/json");
AddMethodOverrideHeader(HttpMethod.Post);
AddCommonHeaders();
var addvCeditsResponseMessage = await HttpClient
.PostAsync(string.Format(Resources.Home + Resources.Credits), content)
.ConfigureAwait(false);
return await Deserialize<CreditsResponse>(addvCeditsResponseMessage);
}
I keep getting a 404 and not sure why. 我不断收到404,但不确定为什么。 Any help on this would be great.
任何帮助都会很棒。
404 means it didn't found the URL you are trying to request to. 404表示找不到您要请求的URL。
I usually have this problem when I have configured POST on the API but do a GET or when I type the endpoint name wrongly (either on client or server side). 当我在API上配置了POST但执行GET时,或者我错误地输入了端点名称(在客户端或服务器端)时,通常会遇到此问题。
Have you validated your API Endpoint and request method? 您是否已验证API端点和请求方法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.