Win7 does not Send Message HttpClient
https://catalog.update.microsoft.com/search.aspx?q=kb3140245
var http = (HttpWebRequest)WebRequest.Create("http://example.com");
var response = http.GetResponse();
var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();
var client = new WebClient();
var content = client.DownloadString("http://example.com");
C:\Windows\system32>netsh http add urlacl url=http://*:8080/ user=SERV-001\gs
Дать работнику процесс счета Олицетворять клиента после проверки подлинности пользователя правильно, выполните следующие действия:
- Нажмите кнопку Пуск, выберите Настройкаи затем панель Управления.
- Дважды щелкните значок Администрирование.
- Дважды щелкните значок Локальная политика безопасности.
- Разверните узел Настройки безопасности, разверните узел Локальные политикии щелкните Назначение прав пользователя.
- В области политики правой кнопкой мыши щелкните Олицетворять клиента после проверки подлинностии выберите команду Свойства.
- Нажмите кнопку Добавить пользователя или группу.
- Добавление учетной записи рабочего процесса, настроенного в элемент processModel файла Machine.config.
- Нажмите кнопку ОК два раза.
- Нажмите кнопку Пуск, щелкните выполнить, введите команду iisresetи нажмите кнопку ОК.
- В командной строке введите следующую команду, чтобы обновить политику на компьютере:
gpupdate/Force
HttpResponseMessage Put(int id, Product item) { ... }
GeoPoint
type, along with a controller method that gets the GeoPoint
from the URI.public class GeoPoint
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
public ValuesController : ApiController
{
public HttpResponseMessage Get([FromUri] GeoPoint location) { ... }
}
GeoPoint
. For example:http://localhost/api/values/?Latitude=47.678558&Longitude=-122.130989
public HttpResponseMessage Post([FromBody] string name) { ... }
POST http://localhost:5076/api/values HTTP/1.1
User-Agent: Fiddler
Host: localhost:5076
Content-Type: application/json
Content-Length: 7
"Alice"
// Caution: Will not work!
public HttpResponseMessage Post([FromBody] int id, [FromBody] string name) { ... }
GeoPoint
class that represents a geographical point, plus a TypeConverter that converts from strings to GeoPoint
instances. The GeoPoint
class is decorated with a [TypeConverter] attribute to specify the type converter. (This example was inspired by Mike Stall’s blog post How to bind to custom objects in action signatures in MVC/WebAPI.)[TypeConverter(typeof(GeoPointConverter))]
public class GeoPoint
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public static bool TryParse(string s, out GeoPoint result)
{
result = null;
var parts = s.Split(',');
if (parts.Length != 2)
{
return false;
}
double latitude, longitude;
if (double.TryParse(parts[0], out latitude) &&
double.TryParse(parts[1], out longitude))
{
result = new GeoPoint() { Longitude = longitude, Latitude = latitude };
return true;
}
return false;
}
}
class GeoPointConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is string)
{
GeoPoint point;
if (GeoPoint.TryParse((string)value, out point))
{
return point;
}
}
return base.ConvertFrom(context, culture, value);
}
}
GeoPoint
as a simple type, meaning it will try to bind GeoPoint
parameters from the URI. You don't need to include [FromUri] on the parameter.public HttpResponseMessage Get(GeoPoint location) { ... }
http://localhost/api/values/?location=47.678558,-122.130989
bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext);
GeoPoint
objects.public class GeoPointModelBinder : IModelBinder
{
// List of known locations.
private static ConcurrentDictionary<string, GeoPoint> _locations
= new ConcurrentDictionary<string, GeoPoint>(StringComparer.OrdinalIgnoreCase);
static GeoPointModelBinder()
{
_locations["redmond"] = new GeoPoint() { Latitude = 47.67856, Longitude = -122.131 };
_locations["paris"] = new GeoPoint() { Latitude = 48.856930, Longitude = 2.3412 };
_locations["tokyo"] = new GeoPoint() { Latitude = 35.683208, Longitude = 139.80894 };
}
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelType != typeof(GeoPoint))
{
return false;
}
ValueProviderResult val = bindingContext.ValueProvider.GetValue(
bindingContext.ModelName);
if (val == null)
{
return false;
}
string key = val.RawValue as string;
if (key == null)
{
bindingContext.ModelState.AddModelError(
bindingContext.ModelName, "Wrong value type");
return false;
}
GeoPoint result;
if (_locations.TryGetValue(key, out result) || GeoPoint.TryParse(key, out result))
{
bindingContext.Model = result;
return true;
}
bindingContext.ModelState.AddModelError(
bindingContext.ModelName, "Cannot convert value to Location");
return false;
}
}
http://localhost/api/values/1?location=48,-122
, the value provider creates the following key-value pairs:GeoPoint
, the model binder assigns the bound value to the ModelBindingContext.Model property.public HttpResponseMessage Get([ModelBinder(typeof(GeoPointModelBinder))] GeoPoint location)
[ModelBinder(typeof(GeoPointModelBinder))]
public class GeoPoint
{
// ....
}
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
var provider = new SimpleModelBinderProvider(
typeof(GeoPoint), new GeoPointModelBinder());
config.Services.Insert(typeof(ModelBinderProvider), 0, provider);
// ...
}
}
public HttpResponseMessage Get([ModelBinder] GeoPoint location) { ... }
public class CookieValueProvider : IValueProvider
{
private Dictionary<string, string> _values;
public CookieValueProvider(HttpActionContext actionContext)
{
if (actionContext == null)
{
throw new ArgumentNullException("actionContext");
}
_values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var cookie in actionContext.Request.Headers.GetCookies())
{
foreach (CookieState state in cookie.Cookies)
{
_values[state.Name] = state.Value;
}
}
}
public bool ContainsPrefix(string prefix)
{
return _values.Keys.Contains(prefix);
}
public ValueProviderResult GetValue(string key)
{
string value;
if (_values.TryGetValue(key, out value))
{
return new ValueProviderResult(value, value, CultureInfo.InvariantCulture);
}
return null;
}
}
public class CookieValueProviderFactory : ValueProviderFactory
{
public override IValueProvider GetValueProvider(HttpActionContext actionContext)
{
return new CookieValueProvider(actionContext);
}
}
public static void Register(HttpConfiguration config)
{
config.Services.Add(typeof(ValueProviderFactory), new CookieValueProviderFactory());
// ...
}
public HttpResponseMessage Get(
[ValueProvider(typeof(CookieValueProviderFactory))] GeoPoint location)
public abstract class ParameterBindingAttribute : Attribute
{
public abstract HttpParameterBinding GetBinding(HttpParameterDescriptor parameter);
}
if-match
and if-none-match
headers in the request. We'll start by defining a class to represent ETags.public class ETag
{
public string Tag { get; set; }
}
if-match
header or the if-none-match
header.public enum ETagMatch
{
IfMatch,
IfNoneMatch
}
public class ETagParameterBinding : HttpParameterBinding
{
ETagMatch _match;
public ETagParameterBinding(HttpParameterDescriptor parameter, ETagMatch match)
: base(parameter)
{
_match = match;
}
public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider,
HttpActionContext actionContext, CancellationToken cancellationToken)
{
EntityTagHeaderValue etagHeader = null;
switch (_match)
{
case ETagMatch.IfNoneMatch:
etagHeader = actionContext.Request.Headers.IfNoneMatch.FirstOrDefault();
break;
case ETagMatch.IfMatch:
etagHeader = actionContext.Request.Headers.IfMatch.FirstOrDefault();
break;
}
ETag etag = null;
if (etagHeader != null)
{
etag = new ETag { Tag = etagHeader.Tag };
}
actionContext.ActionArguments[Descriptor.ParameterName] = etag;
var tsc = new TaskCompletionSource<object>();
tsc.SetResult(null);
return tsc.Task;
}
}
ETagParameterBinding
, we’ll define two attributes, one for if-match
headers and one for if-none-match
headers. Both derive from an abstract base class.public abstract class ETagMatchAttribute : ParameterBindingAttribute
{
private ETagMatch _match;
public ETagMatchAttribute(ETagMatch match)
{
_match = match;
}
public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
{
if (parameter.ParameterType == typeof(ETag))
{
return new ETagParameterBinding(parameter, _match);
}
return parameter.BindAsError("Wrong parameter type");
}
}
public class IfMatchAttribute : ETagMatchAttribute
{
public IfMatchAttribute()
: base(ETagMatch.IfMatch)
{
}
}
public class IfNoneMatchAttribute : ETagMatchAttribute
{
public IfNoneMatchAttribute()
: base(ETagMatch.IfNoneMatch)
{
}
}
[IfNoneMatch]
attribute.public HttpResponseMessage Get([IfNoneMatch] ETag etag) { ... }
ETagParameterBinding
with if-none-match
:config.ParameterBindingRules.Add(p =>
{
if (p.ParameterType == typeof(ETag) &&
p.ActionDescriptor.SupportedHttpMethods.Contains(HttpMethod.Get))
{
return new ETagParameterBinding(p, ETagMatch.IfNoneMatch);
}
else
{
return null;
}
});
null
for parameters where the binding is not applicable.