简体   繁体   English

如何传递值以从php文件请求对象

[英]how to pass values to request object from php file

I am having a small problem. 我有一个小问题。 I have developed ac# file which accepts data in Request object. 我已经开发了一个ac#文件,该文件在Request对象中接受数据。 the Request object contains a string and then i performs various operations on that string but the problem is that I need to call this aspx file from a PHP file. Request对象包含一个字符串,然后我对该字符串执行各种操作,但是问题是我需要从PHP文件调用此aspx文件。

This is how i am accepting data in the ASPX file 这就是我接受ASPX文件中的数据的方式

protected void Page_Load(object sender, EventArgs e)
    {
        try{
            byte[] byteArray;

            byteArray = Request.BinaryRead(Request.TotalBytes);

               // This bytes array to string method perfectly converts the request data into string.
            string xmlString = Utility.Utility.ByteArrayToString(byteArray);

now if i am passing a JSON string from PHP file then please guide me how can i do that 现在,如果我要从PHP文件传递JSON字符串,请指导我如何做

If it is a JSON string then you could use a JSON serializer in order to parse deserialize this string into a class. 如果它是JSON字符串,则可以使用JSON序列化程序将此字符串反序列化为一个类。 For example you could use the built-in JavaScriptserializer class or Json.NET . 例如,您可以使用内置的JavaScriptserializer类或Json.NET

Let's suppose that the PHP file sent the following JSON to the body of a POST request: 假设PHP文件将以下JSON发送到POST请求的正文中:

{"foo":"bar","baz":123}

Now you could define a corresponding model that will match this JSON structure: 现在,您可以定义一个匹配此JSON结构的相应模型:

public class MyModel
{
    public string Foo { get; set; }
    public int Baz { get; set; }
}

and then read the JSON payload from the request and use the serializer to deserialize it back to your model: 然后从请求中读取JSON有效负载,并使用序列化器将其反序列化回模型:

protected void Page_Load(object sender, EventArgs e)
{
    using (var reader = new StreamReader(Request.InputStream))
    {
        string json = reader.ReadToEnd();
        var serializer = new JavaScriptSerializer();
        MyModel model = serializer.Deserialize<MyModel>(json);
        // you could use the model here
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将字符串值从类文件传递到Mvc控制器 - How to pass string values from Class file to Mvc Controller 在SecureConnection上从http重定向到https无法在POST请求中传递值。 我该如何保存它们? - Redirecting from http to https on SecureConnection is unable to pass values in POST request. How can I preserve them? 将对象传递到肥皂请求中 - Pass an object into a soap request 如何传递C#中的列表对象中的值? - How to pass values that are in a List Object in C#? 如何仅将脏值从客户端数据传输对象传递到服务器端域模型 - How to pass dirty values only from client side data transfer object to server side domain model 家庭作业如何将值从一种形式传递到另一种形式的列表中的对象 - Homework how to pass values from one form to an object in a list in another form 如何通过字典传递表格值 <String, String> 到C#中的对象 - How Do i pass form values from a Dictionary <String, String> to an Object in C# 如何将DateTime对象传递给从PHP用C#编写的Soap Web服务? - How can I pass a DateTime object to a Soap web service written with C# from PHP? 如何在Visual Studio中的http Get请求中传递对象参数 - How to Pass Object Parameter in http Get Request in visual studio 如何从c#windows应用程序向PHP服务器发送包含对象数组的POST请求? - How to send POST request containing array of object to PHP server from c# windows application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM