Из https://github.com/slim-template/slim#verbatim-text-
style
|
.card {
height: 100px;
text-align: center;
}
или https://github.com/slim -Tamplate / Slim # Embedded-Engines-Markdown-
css:
.card {
height: 100px;
text-align: center;
}
Ваш HTML-файл не будет взаимодействовать с C # напрямую, но вы можете написать немного C #, чтобы он вел себя так, как если бы это был HTML-файл.
Например: существует класс System.Net.WebClient с простыми методами:
using System.Net;
using System.Collections.Specialized;
...
using(WebClient client = new WebClient()) {
NameValueCollection vals = new NameValueCollection();
vals.Add("test", "test string");
client.UploadValues("http://www.someurl.com/page.php", vals);
}
Дополнительную документацию и функции см. На странице MSDN.
У меня была похожая проблема в MVC (которая привела меня к этой проблеме).
Я получаю FORM в виде строкового ответа от запроса WebClient.UploadValues (), который я затем должен отправить - поэтому я не могу использовать второй WebClient или HttpWebRequest. Этот запрос вернул строку.
using (WebClient client = new WebClient())
{
byte[] response = client.UploadValues(urlToCall, "POST", new NameValueCollection()
{
{ "test", "value123" }
});
result = System.Text.Encoding.UTF8.GetString(response);
}
Мое решение, которое можно использовать для решения OP, состоит в том, чтобы добавить Javascript auto submit в конец кода, а затем с помощью @ Html.Raw () отобразить его на странице Razor. 115]
result += "<script>self.document.forms[0].submit()</script>";
someModel.rawHTML = result;
return View(someModel);
Razor Code:
@model SomeModel
@{
Layout = null;
}
@Html.Raw(@Model.rawHTML)
Надеюсь, это поможет любому, кто окажется в такой же ситуации.
Вот пример сценария, который я недавно использовал в транзакции POST шлюза, которая получает ответ GET. Вы используете это в специальной форме C #? Независимо от вашей цели, просто замените поля String (имя пользователя, пароль и т. Д.) Параметрами из вашей формы.
private String readHtmlPage(string url)
{
//setup some variables
String username = "demo";
String password = "password";
String firstname = "John";
String lastname = "Smith";
//setup some variables end
String result = "";
String strPost = "username="+username+"&password="+password+"&firstname="+firstname+"&lastname="+lastname;
StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally {
myWriter.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
Для этого можно использовать класс HttpWebRequest .
Пример здесь :
using System;
using System.Net;
using System.Text;
using System.IO;
public class Test
{
// Specify the URL to receive the request.
public static void Main (string[] args)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);
// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
}
}
/*
The output from this example will vary depending on the value passed into Main
but will be similar to the following:
Content length is 1542
Content type is text/html; charset=utf-8
Response stream received.
<html>
...
</html>
*/
Response.Write("<script> try {this.submit();} catch(e){} </script>");