我正在使用AFHTTPRequestOperationManager将一些JSON发布到我的服务器,我的代码如下.
NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAndKeys:@"john", @"name", @"xxxxx@gmail.com", @"email", @"xxxx", @"password", @"1", @"type", nil];
// Do any additional setup after loading the view.
AFSecurityPolicy *policy = [[AFSecurityPolicy alloc] init];
[policy setAllowInvalidCertificates:YES];
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
[operationManager setSecurityPolicy:policy];
[operationManager POST:@"posturl here" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", [responseObject description]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", [error description]);
}];
Run Code Online (Sandbox Code Playgroud)
响应如下:
2013-11-18 16:49:29.780 SwapOnceApiTester[12651:60b] Error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: unsupported media type (415), got 1664256" UserInfo=0x1565a6c0 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试解决一个问题。我必须从 Azure 托管的 Web API 访问托管在本地服务器 (on-prem) 上的 API。
问题是我的本地服务器只允许列入白名单的 IP。我知道我们可以从我们的 Web 应用程序(Azure 托管)获取出站 IP。但我不确定它们是静态的还是会根据缩放而改变。
另一个解决方案是创建 VNET 并将该 Web 应用程序添加到该 VNET 中。但我希望有人提出更好的解决方案。
azure azure-virtual-network azure-app-service-plans azure-application-gateway
我正在尝试解析 CSV,但遇到了一些问题。以下是我用于解析 CSV 的代码:
let fileURL = Bundle.main.url(forResource: "test_application_data - Sheet 1", withExtension: "csv")
let content = try String(contentsOf: fileURL!, encoding: String.Encoding.utf8)
let parsedCSV: [[String]] = content.components(separatedBy: "\n").map{ $0.components(separatedBy: ",")}
Run Code Online (Sandbox Code Playgroud)
这是我正在解析的 CSV 中的数据:
Item 9,Description 9,image url
"Item 10 Extra line 1 Extra line 2 Extra line 3",Description 10,image url
Run Code Online (Sandbox Code Playgroud)
因此,通过使用上面的代码,我得到了第一行的正确响应,即Item 9
但我得到了格式错误的响应Item 10
如何正确解析两行?
我正在处理需求,其中我检查了我们的请求标头是否包含授权标头,并基于该要求调用另一个服务器并返回 403。目前我已经通过创建自定义 ActionAttribute 来完成它,如下所示:
public class ValidateAuthHeaderAttribute: ActionFilterAttribute
{
private readonly ILogger<ValidateAuthHeaderAttribute> _logger;
public ValidateAuthHeaderAttribute(ILogger<ValidateAuthHeaderAttribute> logger)
{
_logger = logger;
}
public override void OnActionExecuting(ActionExecutingContext context)
{
var httpContext = context.HttpContext;
if (httpContext.Request.Headers.ContainsKey("Authorization"))
{
return;
}
var failureResponse = new FailureResponseModel
{
Result = false,
ResultDetails = "Authorization header not present in request",
Uri = httpContext.Request.Path.ToUriComponent(),
Timestamp = DateTime.Now.ToString("s", CultureInfo.InvariantCulture),
Error = new Error
{
Code = 108,
Description = "Authorization header not present in request",
Resolve = "Send Request …
Run Code Online (Sandbox Code Playgroud) 我正在使用concat在我的方法中加入2个字符串,但是我遇到的情况是,如果String A / B为null,而不是用String A / B合并,则它应该为空。像这样
var message = "ABC" + Null;
Run Code Online (Sandbox Code Playgroud)
所以我要寻找的是message = ""
不是ABC
我该如何在C#中做到这一点